moose

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 would like to understand WHY my method is not working. The singleton role I have written...

Alternatives to storing Moose object using Apache::Session with CODE references

I have a Moose class that i would like to store using Apache::Session::File. However, Apache::Session::File by default will not store it and instead i get the error message: (in cleanup) Can't store CODE items at blib\lib\Storable.pm (autosplit into blib\lib\auto\Storable\_freeze.al)... This problem can be circumvented by setting $...

Is Moose really this slow?

I recently downloaded Moose. Experimentally, I rewrote an existing module in Moose. It seems to be convenient way to avoid writing lots of repetitive code. I ran the tests of the module, and I noticed it was a bit delayed. I profiled the code with -d:DProf and it seems that just including the line no Moose; in the code increases the r...

In Moose subroutines, how does $meta get into @_ ?

chromatic's recent blog got me curious about the Moose subroutine has. I was looking at the Moose source code and noticed that inside the has subroutine, there is a $meta variable unpacked from @_. Where does $meta come from? I've started wading through the various Moose and Class::MOP modules. In many subroutines, it seems that $meta is...

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 variant: (ref $obj)->new() $obj->meta->new_object() And, then what if you have traits? Is t...

Argument for builder subroutine in a moose object

I'm currently delegating the builder method to all of the objects that extend one of my base classes. The problem that I'm facing is I need all of the objects to either read an attribute of itself or be passed in a value. # In Role: has 'const_string' => ( isa => 'Str', is => 'ro', default => 'test', ); has 'attr...

How do I turn Moose objects into JSON for use in Catalyst?

I have a series of Moose objects that I'm looking to feed to JSON::XS by way of Catalyst::View::JSON. JSON::XS is unable to encode blessed data-structures. I know that there is MooseX::Storage::Format::JSON which can -- kinda -- do what I want; but, it seems pretty overly heavy. What I'm looking for is essentially the same information th...

What is the most efficient way to override an attribute in lots of my Moose based sub classes?

I am using HTML::FormHandler. To use it one is supposed to subclass from it and then you can override some attributes such as field_name_space or attribute_name_space. However, I now have lots of forms all extending HTML::FormHandler or its DBIC based variant HTML::FormHandler::Model::DBIC and therefore have these overidden attributes ...

How do you name a class/package/module like...

How would you name a package who's sole purpose was to extend another module so you could apply roles to it? I need a package that extends (sub classes) Template::Context with Moose So I can then create roles and traits to apply to it, but I don't know what to name this package (class). Any advice? ...

Pass variables around the around method modifier

Is it possible to pass variables between multiple calls to the around MethodModier? example (that doesn't work but hopefully conveys what I want to do) sub mysub { ... }; around 'mysub' => sub { my $orig = shift; my $self = shift; my $value = get_value; $self->orig(@_); }; around 'mysub' => sub { my $orig = shift; ...

Can I order order method modifiers loaded as part of traits?

This is a follow up to a previous question. if I have multiple plugins/traits with around modifiers, is it possible to ensure a certain execution order (seeing as how I can't be sure which will actually get loaded)? or can I really only control that in code I write and with documentation? Example: I have 3 Roles each with an around and ...

accessing a Moose Array

Having trouble figuring out the syntax (which I'm sure is obvious and I'm stupid) for pushing to a Moose array. This is a continuation of this question. it seems to me that I need to more than a simple value for my specific case. Trying to implement it using a Moose-ish way (maybe that's wrong?) but I'm obviously not doing it right. use...

Using the perl MooseX extention in silent mode?

I have perl 5.10.1 installed on my ubuntu machine. I wanted to install the Moose and MooseX extentions, so I did install the packages with the aptitude package manager. Here are all the packages I have installed: $ sudo apt-cache pkgnames | grep moose libmoosex-singleton-perl libmoosex-compiletime-traits-perl libmoosex-types-structured-...

Need help installing MooseX::Declare

I am running with Perl 5.10.1 installed using the package manager. I have successfully installed Moose from the CPAN shell, and I have tried to install the MooseX::Declare extention without success.. Here is what I have done: $ sudo cpan > cpan.log cpan[1]> install MooseX::Declare Cannot determine perl version info from lib/MooseX/...

Not Able to Set Class' Attributes in Role

Hello all, First off, I'm not really sure how much information is necessary to include because I'm having a really hard time tracing the origin of this problem. I have a Moose role with a subroutine that (along with a few other things) tries to set the attributes for a class like this: $genre = Movie::Genre->new({ genreName => 'Dr...

A Moose role of roles

I'd like to set up a convenience Moose role made up of other smaller roles. For example, if I have WithAddress and WithPhone I would like a single WithContacts that provides both WithAddress and WithPhone and anything contact methods I add in the future. How can I do this with Moose? ...

Deep cloning Moose object with attributes that are ArrayRef[Object] and Set::Object

I've got a Moose object: class My::Game { has 'players' => (isa => 'Set::Object', ...) has 'action_sequence' => (isa => 'ArrayRef[My::Game::Action]', ...) } Now I want to be able to clone this object with a call like $game2 = $game->clone; How do I deep clone it so that the objects in the ArrayRef are cloned? And more trickily, th...

MooseX::Declare and Perl EPIC (Eclipse IDE)?

How can I get support for jumping to Moose methods using Eclipse with the EPIC plugin? (Using F3) They're declared like class Point { method getDistance { ... } } ...

ctags support for MooseX::Declare? (Perl)

How can I get ctags to generate tags for MooseX::Declare methods, classes, attributes and such? ...

Checking a Moose role against a non Moose class.

Hi, let's say you've got a Moose class that requires an attribute that does a Role: package MyMooseClass; use Moose; has 'a' => ( does => 'MyRole' ); Now, I'd like to build an instance of MyMooseClass like this: my $instance = MyMooseClass->new( { a => $a_non_moose_stuff } ); Where $a_non_moose_stuff is an instance of a non-moose ...