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
10
votes
2 answers

what is the best way to string overload on a Moose attribute accessor?

I have a class where I want to apply string overloading on its id attribute. However, Moose doesn't allow string overloading on attribute accessors. For example: package Foo; use Moose; use overload '""' => \&id, fallback => 1; has 'id' => ( is…
stevenl
  • 6,736
  • 26
  • 33
10
votes
2 answers

How do you create subtypes in Moose?

I'm just starting to use Moose. I'm creating a simple notification object and would like to check inputs are of an 'Email' type. (Ignore for now the simple regex match). From the documentation I believe it should look like the following code: # ---…
CoffeeMonster
  • 2,160
  • 4
  • 20
  • 34
10
votes
2 answers

Succinct MooseX::Declare method signature validation errors

I've been a proponent of adopting Moose (and MooseX::Declare) at work for several months. The style it encourages will really help the maintainability of our codebase, but not without some initial cost of learning new syntax, and especially in…
Adam Pingel
  • 681
  • 4
  • 19
10
votes
3 answers

Do Mojolicious and Moose play well together?

I'm working on a Mojo app and I'd like to be able to consume some Moose roles to make my life easier. On CPAN I see MojoX::Moose::Controller, which has very simple internals. I don't see much else on using Moose with Mojo. Any potential issues I…
oalders
  • 5,239
  • 2
  • 23
  • 34
10
votes
3 answers

In Moose, how do I set multiple defaults with one method call?

I have two object attributes which require expensive calculations, so I'd like them to be lazy. They're most efficiently calculated together, so I'd like to calculate them at the same time. Does Moose provide a way to do this? What I'd like is…
Schwern
  • 153,029
  • 25
  • 195
  • 336
10
votes
3 answers

What should I do if a Moose builder method fails?

What is the best way to handle a failure in a builder method? For example: package MyObj; use Moose; use IO::File; has => 'file_name' ( is => 'ro', isa => 'Str', required =>1 ); has => 'file_handle' ( is => 'ro', isa => 'IO::File',…
daotoad
  • 26,689
  • 7
  • 59
  • 100
10
votes
4 answers

How can I extend Moose's automatic pragma exports?

You know how Moose automatically turns on strict and warnings during import? I want to extend that behavior by turning on autodie and use feature ':5.10' in my Moose classes. I've tracked down where Moose does this, in Moose::Exporter, which…
friedo
  • 65,762
  • 16
  • 114
  • 184
10
votes
6 answers

How can I improve Moose performance in non-persistent CGI processes?

Moose is a fantastic object framework. The trouble is that, taken together with its dependencies, it's very big. Our profiling indicates that on our platform, simply loading Moose will incur a 5-6 second overhead on non-persistent CGI application…
Adam Bellaire
  • 108,003
  • 19
  • 148
  • 163
9
votes
5 answers

Is there a really good web resource on moving to Moose?

The documentation with the module itself is pretty thin, and just tends to point to MOP.
Axeman
  • 29,660
  • 2
  • 47
  • 102
9
votes
4 answers

Dependency injection for Moose classes

I have a Moose class that needs to send requests of type Foo::Request. I need to make this dependency accessible from the outside, so that I can easily exchange the request implementation in tests. I came up with the following attribute: has…
zoul
  • 102,279
  • 44
  • 260
  • 354
9
votes
1 answer

Moose method modifiers on DBIx::Class::Schema models in Catalyst

For any given result class MySchema::Result::Foo (built from default schema loader generated syntax which uses Moose/MooseX::nonmoose) If I add a BUILDARGS method wrapper to sanitize the constructor data for a row like so: package…
nebulous
  • 738
  • 6
  • 17
9
votes
3 answers

Why is Moose code so slow?

I'm trying to parse a large XML file. I read it using XML::SAX (using Expat, not the perl implementation) and put all the second level and below nodes into my "Node" class: package Node; use Moose; has "name" => ( isa => "Str", reader =>…
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
9
votes
5 answers

Perl OO frameworks and program design - Moose and Conway's inside-out objects (Class::Std)

This is more of a use-case type of question... but also generic enough to be more broadly applicable: In short, I'm working on a module that's more or less a command-line wrapper; OO naturally. Without going into too many details (unless someone…
Emmel
  • 298
  • 1
  • 11
9
votes
2 answers

How do I represent a mixin/role/trait with UML properly?

Me and several other developers are currently cleaning up our legacy code base, mostly separating visual and data layers. To help developers not involved in this refactoring understand the model, I'd like to introduce a (rather informal) class…
Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
9
votes
3 answers

How do I call a function name that is stored in a hash in Perl?

I'm sure this is covered in the documentation somewhere but I have been unable to find it... I'm looking for the syntactic sugar that will make it possible to call a method on a class whose name is stored in a hash (as opposed to a simple…
Ether
  • 53,118
  • 13
  • 86
  • 159
1 2
3
40 41