moose

Moose: Expiring cached results of calculations when attribute values change?

In our classes we have a pattern where we create an attribute to represent a calculated value. For obvious reasons we want to cache the calculated value and then invalidate the cache when one of the underlying values change. So we currently have this: package FooBar; use Moose; has 'foo' => ( accessor => { 'foo' ...

Is implementing SOAP clients in Perl using meta-programming sensible?

I'm currently dealing with a code base which contains several dozens of classes generated with SOAP::WSDL. However, having worked with Moose I now think that generating those classes at runtime at meta level (i.e. not to files on disk but directly to objects) might be a better idea (completely excluding performance reasons at this point)...

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 constructor no longer gets inherited and I get the fatal error: Can't locate object method ...

Is it possible to retrieve existing moose objects, rather than create a new one, when the same required attributes are provided?

Suppose i have the following Moose package: package GSM::Cell; use Moose; has 'ID' => (is => 'ro', required => 1); has [qw(BCCH NEIGHBOUR)] => (is => 'rw', default => undef); no Moose; __PACKAGE__->meta->make_immutable; 1; I then create two objects and add the one as the 'NEIGHBOUR' attribute of the other: my $a = GSM::Cell->new(I...

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 do not want the following to work: my $prodid = SOD::KuuAnalyze::ProdId->new(users => ["...

Is there any way I can use Moose::Exporter from within a Moose object?

I'm looking for a way to set up some helper methods from within a parent Moose class, rather than a standalone utility class. If it is possible, it would be a more transparent way of adding Moose sugar to modules, as it does not require explicitly requiring any helper modules (as everything would come via the extends declaration). Based...

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 scalar): use strict; use warnings; package Foo; sub foo { print "in foo()\n" } package main; my %...

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 the amount of dereferencing that the user of the class has to do, but it will mean they can'...

How do I create an instance of value from the attribute's meta object with Moose?

I'm working on a serialization tool using Moose to read and write a file that conforms to a nonstandard format. Right now, I determine how to load the next item based on the default values for the objects in the class, but that has its own drawbacks. Instead, I'd like to be able to use information in the attribute meta-class to generat...

How can I find all the packages that inherit from a package in Perl?

I have a number of different sites that I download data from and massage into other formats (using Perl) for use at work, that are all run from one Perl script kinda like so: #! /usr/bin/perl use strict; use My::Package1; use My::Package2; my $p1 = My::Package1->new; $p1->download; my $p2 = My::Package2->new; $p2->download; and so ...

How can I assign many Moose attributes at the same time?

I'm gradually Moose-ifying some code that reads lines from a pipe delimited, splits each and assigns adds them to a hash using a hash slice. I've turned the hash into a Moose class but now I have no idea how to quickly assign the fields from the file to the attributes of the class (if at all). I know I can quite easily just do: my $li...

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', lazy_build => 1 ); sub _build_file_handle { my $self = shift; my $fh = IO::File->new(...

Is there a vim plugin that makes Moose attributes show up in Tag_List?

I am editing packages that use Moose, and I was wondering if there were a plugin for making Moose attributes show up in the Tag List. For example, in the following code, the attribute options does not show up in Tag_List, but print_out_site does: use Moose; use MooseX::AttributeHelpers; ... has 'options' => ( metaclass => 'Collec...

How can I report the line number with Log4perl and Moose?

Is it possible to get Log4perl to correctly display the line number and package/class of the log event instead of always Method::Delegation at line 99 when used with Moose? In my case, I have created an attribute isa Log::Log4perl::Logger and delegated the various logging levels to my class (log, warn, error, ...). Doing this also show...

How can I get structured exceptions from Moose?

Consider this simple class: package Foo; use Moose; has foo => ( is => 'rw', isa => 'Int' ); And then this code: use Try::Tiny; use Foo; my $f = try { Foo->new( foo => 'Not an Int' ); } catch { warn $_; }; The code dies with a nice big error message about type constraints failing. I'd like to be able to extract what attrib...

Why doesn't Moose role application with method modifiers work in my code?

I have a Role and several classes that mix-in the role. The Role class loads all of the implementing classes so that anything that imports Blah can use them without typing a lot of 'use' lines. package Blah; use Moose::Role; use Blah::A; use Blah::B; (etc...) requires '...'; requires 'foo'; around 'foo' => sub { ... } A typical Blah...

How much do I need to test Moose- and MooseX::FollowPBP-generated methods?

I want to start strictly doing Test-Driven-Development. However, I was wondering how much I should test methods generated by Moose and MooseX::FollowPBP. For example, I have the following class: package Neu::Series; use Moose; use MooseX::FollowPBP; use File::Find::Wanted; has 'file_regex' => ( isa=>'RegexpRef', is=>'rw', ...

Is there an easy way to map DBIx::Class results to my custom Moose classes?

It seems kind of a pain to have my Moose classes. Then to use DBIx::Class to get a result set..then to manually map my result set to the moose classes. ...

Are MooseX::Declare and MooseX::Method::Signatures production ready?

From the current version (0.98) of the Moose::Manual::MooseX are the lines: We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare. However, these modules, while used regularly in production by some of the more insane members of the community, are still marked alpha just in case backwards in...

Is checking Perl function arguments worth it?

There's a lot of buzz about MooseX::Method::Signatures and even before that, modules such as Params::Validate that are designed to type check every argument to methods or functions. I'm considering using the former for all my future Perl code, both personal and at my place of work. But I'm not sure if it's worth the effort. I'm thinking...