moose

Shorthand for referring to Perl/Moose package names?

In both Python and Java we have import to eliminate the repetition of fully-qualified package/module names throughout code. Is there any equivalent in Perl/Moose? I think it would really make Moose nicer to use if we didn't have to repeat MyApp::Model::Item. Instead, I'd like to [somehow declare] MyApp::Model::Item; and later on, simply ...

Import MooseX::Method::Signatures into caller's scope

I've made a "bundle" module which does a bunch of things: imports Moose, imports true, namespace::autoclean, makes the caller's class immutable (taken from MooseX::AutoImmute). The one thing I haven't been able to figure out is how to include MooseX::Method::Signatures. Here's what I've got so far: package My::OO; use Moose::Exporter;...

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 warnings; use Carp qw//; BEGIN { *CORE::GLOBAL::require = sub (*) { warn "Requiring...

How can I acces read-only attributes of Moose objects?

I'm an absolute newbie to Moose and so far I have read Moose and most of the Cookbook. There a few things I don't get. I created the following package: package MyRange; use Moose; use namespace::autoclean; has [ 'start', 'end' ] => ( is => 'ro', isa => 'Int', required => 1, ); __PACKAGE__->meta->make_immutable...

How should I store and compress a Moose object using Perl?

I have created a package using Moose and I would like to nstore some large instances. The resulting binary files are very large (500+MB) so I would like to compress them. What is the best way for doing that? Should I open a filehandle with bzip etc. then store using fd_nstore? ...

How should I control versions of my Perl Moose objects?

I'm a Moose newbie and I wonder if the common our $VERSION = "0.001"; $VERSION = eval $VERSION; should also be used in Moose packages, or Moose has some alternative way for version control. Couldn't find a reference in Moose docs. ...

Why do I get many Moose warnings when I start Catalyst?

Hi everyone, I am having an issue (Catalyst related) apparently with Moose/Class::MOP. Starting my server I get the following output... (shown below in all its glory) The alias and excludes options for role application have been renamed -alias and -excludes at /usr/local/lib/perl/5.10.1/Moose/Meta/Role/Application.pm line 26 Moose:...

In Moose, how do you declare predicate and clearer methods when defining multiple attributes?

In Moose you can declare a group of attributes at once, assuming the initialization parameters are the same: has [qw( foo bar baz )] => ( is => 'ro', isa => 'Str', required => 1, ); This is a lovely feature that saves a ton of typing. However, I find myself puzzled about how define a predicate, clearer or even a builder m...

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 => 'getName' ); has "text" => ( is => "rw", isa => "Str" ); has "attrs" => ( ...

perl Moose accessor madness - can't define only a reader or writer accessor!

So I'm just trying to do a very simple thing: define a custom reader accessor for a moose attribute. So I try this: has 'compiled_regex' => ( isa => 'RegexpRef', is => 'rw', reader => 'get_compiled', ); but get_compiled never gets called, presumably because compiled_regex is read/write. Ok, no problem. I next try th...

In Moose, how can I make a class's constructor return an instance of a subclass?

Possible Duplicate: How to have Moose return a child class instance instead of its own class, for polymorphism Suppose I have two related classes MyClass::A and MyClass::B that are both subclasses of MyClass. I would like the constructor for MyClass to take a filename, read the file, and based on the contents of the file, deci...

In Moose, how can I tell whether one object's class is a subclass of another object's class?

Suppose I have two objects $obj1 and $obj2 that are both instances of Moose classes. I want to find out which of the following applies: $obj1's class is the same as $obj2's; $obj1's class is a subclass of $obj2's; $obj1's class is a superclass of $obj2's; Neither object's class is a subclass of the other's. How can I do this? ...

Perl: fixing Moose attribute and type coercion problems

I recently upgraded Moose to v1.15 and found that a set of modules I use no longer worked. The error I get is: You cannot coerce an attribute (source) unless its type (GOBO::Node) has a coercion at /opt/local/lib/perl5/site_perl/5.12.0/darwin-multi-2level/Moose/Meta/Role/Application/ToClass.pm line 142 I can see several possible sourc...

Is there a Perl module for converting YAML files into Moose objects dynamically at runtime?

I've been trying to find a Perl module that converts a YAML file into moose objects without having to pre-declare the structure as you seem to need to do when using MooseX::YAML. Does anyone know of such a module (or script)? ...

How should I maintain my object modules in Perl?

I'm writing some object module in Perl using Moose. I use to store instances of created objects then use them. The basic representation of my object's data remains the same, but from time to time I add more functionalities - e.g. class methods or object methods. Can I continue using my stored objects, which were created with an earlier...

How can I create a structure after a Moose object was initialized?

I'm using Moose to write an object module. I currently have a few mandatory fields: has ['length'] => ( is => 'ro', isa => 'Int', required => 1, ); has ['is_verified'] => ( is => 'ro', isa => 'Bool', required => 1, ); has ['url'] => ( is => 'ro', isa => 'Str', requi...

How can I build multiple attributes with a single builder in Moose?

Using Moose, is it possible to create a builder that builds multiple attributes at once? I have a project in which the object has several 'sets' of fields - if any member of the set is requested, I want to go ahead and populate them all. My assumption is that if I need the name, I'll also need the birthdate, and since they're in the sa...

Is it possible to automatically coerce parameters passed to delegated methods (from the Array trait) using Moose/MooseX::Declare for Perl?

I'm creating a class which will contain a list of IP addresses, as Net::IP objects. I've wrapped the Net::IP object as a subtype (IPAddress), and defined a coercion from a string to IPAddress. Then I've added an attribute to the class called ip_list with the type ArrayRef[IPAddress], and delegated to the push method of the Array trait....

How should I define a Moose object subroutine after its initialization?

How should I define a Moose object subroutine after its initialization? I'm writing an object module using Moose and I plan to serialize (nstore) the created objects. Examine the following (simplified!) example: package MyObj 0.001; use Moose; use namespace::autoclean; has 'size' => ( is => 'ro', isa => 'Int', required...

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 simply added a single field called extra of type hashref which is is set to rw, so users can s...