Questions tagged [moose]

Moose is a postmodern object system for Perl 5 that takes the tedium out of writing object-oriented Perl. It borrows all the best features from Perl 6, CLOS (Lisp), Smalltalk, Java, BETA, OCaml, Ruby and more, while still keeping true to its Perl 5 roots.

Moose is an extension of the Perl 5 object system. The main goal of Moose is to make Perl 5 object-oriented programming (OOP) easier, more consistent and less tedious. With Moose you can think more about what you want to do and less about the mechanics of OOP.

Moose links

See Also

sources: moose.perl.org

609 questions
1
vote
1 answer

Attribute accessor not satisfying role requirement when using Moops and Moose

Consider the following code sample: use Moops; role RoleA using Moose { requires 'm1'; method m2() { $self->m1." World!\n"; } } role RoleB using Moose { has 'm1' => ( accessor => 'm1', is => 'ro', isa => 'Str', default =>…
sschober
  • 2,003
  • 3
  • 24
  • 38
1
vote
1 answer

Where does MooseX::Getopt put the unprocessed tokens

I have this fragment package AppOpt; use Moose; use namespace::autoclean; with 'MooseX::Getopt'; has opt1 => (is => 'ro', isa => 'Str', required => 1); has opt2 => (is => 'ro', isa => 'Bool', required =>…
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47
1
vote
1 answer

Overriding import method of a Moose class

I have two Perl classes. Let's call one Client, the other Server. Server is a well defined Moose class. Client is not a Moose class, and is just a very thin facade to connect to a Server object over a network. Furthermore, Client is internal to…
Mike Monkiewicz
  • 4,481
  • 1
  • 22
  • 19
1
vote
1 answer

Moose attribute coercion - MooseX::Types::URI

The synopsis for MooseX::Types::URI says: use MooseX::Types::URI qw(Uri FileUri DataUri); So, my example code: package My; use 5.014; use warnings; use Moose; use MooseX::Types::URI qw(Uri); has 'url' => ( is => 'rw', isa =>…
novacik
  • 1,497
  • 1
  • 9
  • 19
1
vote
2 answers

Perl::Moose: Using a read accessor to return only a calculated value

Thank you for your help! Lets say I have a class Stock: package Stock; use Moose; has 'quantity' => ( is => 'rw', ); has 'price' => ( is => 'rw', ); has 'value' => ( is => 'ro', ); 1; How can I calculate the value (quantity*price) when…
Ted Bear
  • 117
  • 8
1
vote
1 answer

Perl/Moose object initialization with coercion into ArrayRef

Need make a module what accepts one or more paths, and coerce them to array of Class::Path. In the CPAN exists a module MooseX::Types::Path::Class. From it's source I discovered than the module defined subtypes Dir and File. My example…
novacik
  • 1,497
  • 1
  • 9
  • 19
1
vote
2 answers

Simple Moose::Exporter example not working

I am trying to understand Moose::Exporter, but no matter what I try, the example almost as exactly from the manual is not working. package HasRw; use Moose; use Moose::Exporter; Moose::Exporter->setup_import_methods( with_meta =>…
Karel Bílek
  • 36,467
  • 31
  • 94
  • 149
1
vote
1 answer

Remove __CLASS__ From JSON Output of Moose Object In Perl

I'm working with moose objects in perl. I want to be able to covert the moose objects I make directly to JSON. However, when I use use MooseX::Storage to covert the objects, it includes a hidden attribute that I don't know how to remove the …
Bostwick
  • 696
  • 1
  • 12
  • 24
1
vote
2 answers

Moose: Extending Exporter causes constructor to disappear?

Here's something weird that I can't figure out. I have a Moose class that I also want to export some constants, using the age-old standard Exporter module. However, as soon as I add extends Exporter to my class, for some reason, the default Moose…
friedo
  • 65,762
  • 16
  • 114
  • 184
1
vote
0 answers

Carp reporting from the wrong location with @CARP_NOT (Moose and Method Modifiers)

This is a followup question to warnings::warnif( 'deprecated' … ) with carp?. here's a snippet of my code from Business::CyberSource on Github note: the previous answer (in the previous question), and adding of @CARP_NOT have demonstrated that…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
1
vote
2 answers

How do I use a Moose Type as a regex match expression?

I have the following type in my class file: has 'cardNumber' => (is => 'ro', isa => 'Int', required => 1); I am trying to do the following: foreach $_ (@accountsInfo) { if ($_ =~ m/^$self->cardNumber()/) { …
BackPacker777
  • 673
  • 2
  • 6
  • 21
1
vote
1 answer

Override default attribute when using Moose roles

I can't override a already declared attribute in a role with MooseX::Declare. use MooseX::Declare; role Person { has 'name' => ( is => 'ro', isa => 'Str', default => 'John', ); } class Me with Person { has '+name' => ( …
mino
  • 41
  • 5
1
vote
2 answers

Catalyst global moose hash returning MIME type httpd/unix-directory

I'm trying to create a Moose hash in my Catalyst app in my_app.pm so that I can access it globally: has 'hash' => ( is => 'rw', isa => 'Hashref' ); However, as soon as I try to add defaults: has 'hash' => ( is => 'rw', isa =>…
srchulo
  • 5,143
  • 4
  • 43
  • 72
1
vote
1 answer

Calling an object method from array of objects in perl using moose

I have one object that has an attribute of an array of another group of objects. I have a toString method that I want to print out the entire contents of the objects. The main goal is to have the Job object call all the post process jobs that are in…
1
vote
3 answers

Object Attributes Getting Set Without Me Asking

I'm using Moose, maybe it matters, maybe it doesn't. My object comes in as $event, and I save the args attribute value to a variable: my $args = $event->args; That value happens to be a hash, so I do some stuff to the hash, specifically adding a…
Ryan
  • 672
  • 1
  • 6
  • 16