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

How can I integrate Moose into Komodo?

ActiveState's Komodo is my preferred Perl IDE on OS X and XP. Recently I've begun coding new projects using Moose. Has anyone found a way to teach Komodo how to "identify" Moose's Attribute and Method declarations? I would just love to see…
lexu
  • 8,766
  • 5
  • 45
  • 63
8
votes
2 answers

Are there any modern (Moose/PSGI) web frameworks other than Catalyst?

Are there any Perl web-development frameworks other than Catalyst that are: written with Moose natively written for PSGI (not with some PSGI-emulation) Unicode ready/safe - so Perl 5.10+ small, extensible and nice or is Catalyst the only guy in…
cajwine
  • 3,100
  • 1
  • 20
  • 41
8
votes
3 answers

Moose (Perl): convert undef to empty string or 0 rather than die()

I've received a lot of exceptions from QA due to incomplete data being fed to my Moose constructors. The attribute name is present in the constructor arguments, but the value is undef. It's a fact of life with many scripting applications that things…
Lumi
  • 14,775
  • 8
  • 59
  • 92
8
votes
2 answers

Odd behavior with Moose, Try::Tiny, and TryCatch

I've just started working with Moose and have run into an odd problem that I cannot figure out. The following code: #!/usr/bin/env perl use strict; use warnings; use Try::Tiny; { package Foo; use Moose; has x => ( is => 'ro', isa =>…
Joe
  • 197
  • 4
8
votes
3 answers

Useful errors for Moose and MooseX::Declare

Moose is very lovely, but sometimes simple typos can cause hair-raisingly exciting long stacktraces with, from my point of view, zero useful content. So, are there any tools to interpret this exploding into something helpful? In particular for…
Alex
  • 5,863
  • 2
  • 29
  • 46
8
votes
3 answers

How do I handle optional parameters in Moose?

I'm currently starting with Perl OOP using the "Moose" package. The compiler complains that it "Can't modify non-lvalue subroutine call at Parser.pm line 16." I don't quite understand why I can't just assign a new object. I guess there is a better…
Brian Johnson
  • 1,629
  • 5
  • 21
  • 26
8
votes
3 answers

How can I get a better error message if a required attribute is not supplied in Moose?

I'm brand new to Moose. Up until today our environments have been on Perl 5.8.2 which would not support Moose. I'm working through some examples, and I thought that the "required => 1" setting on an attribute would be handy, however when I try…
BrianH
  • 7,932
  • 10
  • 50
  • 71
8
votes
2 answers

Can I define functions outside of a class using MooseX::Declare?

I recently started using the module MooseX::Declare. I love it for its syntax. It's elegant and neat. Has anyone come across cases where you would want to write many functions (some of them big) inside a class and the class definition running into…
sachinjsk
  • 89
  • 3
8
votes
2 answers

Do all my Moose classes have to contain 'namespace::autoclean' and 'make_immutable' or is there some way to get these by default?

According to the Moose best practices doc, my Moose classes should look like this: package Person; use Moose; use namespace::autoclean; # extends, roles, attributes, etc. # methods __PACKAGE__->meta->make_immutable; 1; See…
nick
  • 1,369
  • 2
  • 13
  • 28
8
votes
3 answers

How do I figure out what module is loading Moose?

I am trying to figure out which module in my CGI::Application is loading Moose. I attempted to overload "require" but I don't seem to have the syntax quite right. If someone could clean up the following code I would appreciate it: use strict; use…
Jeffrey Fuller
  • 300
  • 1
  • 2
  • 8
8
votes
4 answers

How can I use Moose with Test::Class?

I'm currently refactoring a test suite built up by a colleague and would like to use Test::Class[::Most] while doing so. As I started I figured out I could really use a couple of Moose roles to decouple code a little bit. However, it seems it's not…
Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
8
votes
2 answers

Unblessing Perl objects and constructing the TO_JSON method for convert_blessed

In this answer I found a recommendation for a simple TO_JSON method, which is needed for serializing blessed objects to JSON. sub TO_JSON { return { %{ shift() } }; } Could anybody please explain in detail how it works? I changed it to: sub TO_JSON…
novacik
  • 1,497
  • 1
  • 9
  • 19
8
votes
3 answers

Moose ArrayRef attribute returned as an Array

I have a Moose class with an attribute that is an ArrayRef (read-only) and is manipulated internally by the object. But when someone calls the accessor method I want it to return an Array (or list) not a reference. Not only would this cut down on…
mpeters
  • 4,737
  • 3
  • 27
  • 41
7
votes
1 answer

How can I set a static variable that can be accessed by all subclasses of the same base class (Perl/Moose)?

Since Perl/Moose always calls the base class' BUILD function before it calls the subclass BUILD function, there is a new instance of the base class everytime you instantiate a subclass. How do I go about creating a static variable that can be used…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
7
votes
1 answer

Moose (Perl): access attribute definitions in base classes

Using __PACKAGE__->meta->get_attribute('foo'), you can access the foo attribute definitions in a given class, which can be useful. #!perl package Bla; use Moose; has bla => is => 'ro', isa => 'Str'; has hui => is => 'ro', isa => 'Str', required =>…
Lumi
  • 14,775
  • 8
  • 59
  • 92