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

Store a Moose object that has a PDL as an attribute

I am new to Moose and doing quite well until I have hit a snag using a PDL as a property. I want to be able to write an object to a file (I have been using use MooseX::Storage; with Storage('io' => 'StorableFile');, and this object has a PDL as a…
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
7
votes
1 answer

How to use Moose to add convenience functions for array attributes?

This is a basic question, I fear. Take a look at the following code. I'd like to know whether there is a way to declare the slices attribute in such a way as to avoid the boilerplate of get_slices and add_slice. package Gurke; use Moose; has slices…
Lumi
  • 14,775
  • 8
  • 59
  • 92
7
votes
3 answers

Why does Moose's builder take a string value?

Moose::Manual::Attributes states: As an alternative to using a subroutine reference [for default], you can instead supply a builder method for your attribute: ... This has several advantages. First, it moves a chunk of code to its own named…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
7
votes
2 answers

How can I overload Moose constructors?

Sorry for the Java jargon, but how can I overload Moose constructors? Suppose I'm representing a segment. I can either take a start point and and point, or a start point and length, or end point and length. How can I allow for such alternative…
David B
  • 29,258
  • 50
  • 133
  • 186
7
votes
4 answers

How can I flexibly add data to Moose objects?

I'm writing a module for a moose object. I would like to allow a user using this object (or myself...) add some fields on the fly as he/she desires. I can't define these fields a priori since I simply don't know what they will be. I currently…
David B
  • 29,258
  • 50
  • 133
  • 186
7
votes
1 answer

Correct way to instantiate a Moose object from another Moose object?

What is the correct way to create an instance from another Moose object? In practice I've seen this done numerous ways: $obj->meta->name->new() $obj->new() ## which has been deprecated and undeprecated (blessed $obj)->new() -- and, its bastard…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
7
votes
4 answers

Singleton Roles in Moose

I am attempting to write a singleton role using Perl and Moose. I understand a MooseX::Singleton module is available but there is always resistance when requiring another CPAN module for our project. After trying this and having a little trouble I…
mjn12
  • 1,853
  • 3
  • 19
  • 27
7
votes
1 answer

Moose::Error::Croak error reporting not from perspective of caller

I just recently started out on Moose and its a great OO framework not only to use but also to learn new OO concepts. One of the things I wanted to do was to do error reporting from perspective of caller during object creation. I saw that Moose has…
Saurabh Hirani
  • 1,198
  • 14
  • 21
7
votes
4 answers

Loading the needed packages on demand in perl

Reworded question - sorry, it is a bit long. Have a simplyfied package for example package My; use Moose; use namespace::sweep; sub cmd1 {1} sub smd2 {2} __PACKAGE__->meta->make_immutable; 1; I want allow to others extending the My with another…
clt60
  • 62,119
  • 17
  • 107
  • 194
7
votes
2 answers

How to setup a DBIx::Class schema with Moose -- the definite guide

I found it rather difficult to find information about how to assemble a DBIx::Class schema structure using Moose. How to do that correctly (essentially working) and in modern Perl (good style, fast, without warnings)? These are my goals: follow…
Daniel Böhmer
  • 14,463
  • 5
  • 36
  • 46
7
votes
2 answers

How to override a sub in a Moose::Role?

I'm trying to implement a Moose::Role class that behaves like an abstract class would in Java. I'd like to implement some methods in the Role, but then have the ability to override those methods in concrete classes. If I try this using the same…
Joel
  • 3,435
  • 2
  • 23
  • 33
7
votes
2 answers

How can I prevent Perl Moose Read-Only Attributes being set upon a call to new?

I would like to simply declare a read only attribute in Moose that cannot be initialized in a call to new. So after declaring the following: package SOD::KuuAnalyze::ProdId; use Moose; has 'users' => (isa => 'ArrayRef[Str]', is => "ro"); 1; I…
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
7
votes
3 answers

How do I create a cyclic graph of immutable objects in Perl and Moose?

This could seem like an obviously hopeless case, but is there a trick to create a cyclic graph of immutable objects in Perl? Something like this: package Node; use Moose; has [qw/parent child/] => (is => 'ro', isa => 'Node'); package main; my $a =…
zoul
  • 102,279
  • 44
  • 260
  • 354
7
votes
1 answer

How can I access the meta class of the module my Moose role is being applied to?

I'm using Moose roles to apply some wrapper behaviour around some accessor methods in a class. I want to apply this role to a number of modules, each of which have a different set of attributes whose accessors I want to wrap. Is there a way to…
Ether
  • 53,118
  • 13
  • 86
  • 159
7
votes
2 answers

Perl Moose attributes with minimum, maximum, and default value

Using Moose, it's possible to create attributes having a default value. I have a set of attributes which all have a minimum, maximum and a default value. They are attributes representing a scale (such as Tk::Scale). Currently, I have at least 3…
capfan
  • 817
  • 10
  • 26