moose

Is there a really good web resource on moving to Moose?

The documentation with the module itself is pretty thin, and just tends to point to MOP. ...

Perl::Critic: Life after Moose?

I've started a conversion of a project to Moose and the first thing I noticed was that my critic/tidy tests go to hell. Moose, Tidy and Critic don't seem to like each each other as much as they used to. Are there docs anywhere on how to make critic/tidy be more appreciative if the Moose dialect? What do most Moose users do? Relax/ditch ...

CLOS like object model for PHP

I have returned to php development from Moose and I really miss CLOS like object model for php. Is there some kind of syntaxtic sugar which would allow me to write less code in php when dealing with objects? Just to stress this requirement a bit more. I don't want to write one thing in several places. I can live with part of code being ...

How can I invoke an object dynamically in Perl Moose OOP?

Here is classical object model: class ViewBase { void DoSomethingForView() { } //May be virtual } class View1 : ViewBase //(derived class from ViewBase) { void DoSomethingForView() { } void DoSomethingForView1Special() { } } class View2: ViewBase //(another derived class from ViewBase) { void DoSomethingForView2S...

How do you do Design by Contract in Perl?

I'm investigating using DbC in our Perl projects, and I'm trying to find the best way to verify contracts in the source (e.g. checking pre/post conditions, invariants, etc.) Class::Contract was written by Damian Conway and is now maintained by C. Garret Goebel, but it looks like it hasn't been touched in over 8 years. It looks like wha...

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 pages? Is there any workaround to make the class definition to just have the functions decl...

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 method, which improves readability and code organization. So, your attribute could defin...

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 or more valid way to do optional parameters with Moose? #!/usr/bin/perl -w package ...

Migrating from Moose to Mouse in Perl - Mouse not executing BUILD

I'm trying to migrate from Moose to Mouse in the interests of speed but have encountered a showstopper error. I'm building two objects in the same scope: sub scope { my $foo = Foo->new(); my $bar = Bar->new(); } The BUILD method of Foo is firing but the BUILD method of Bar is not. Any ideas? Both Foo and Bar inherit from Baz ...

How can I use MooseX::ClassAttribute within a role?

I would like to use MooseX::ClassAttribute in a role. I.e., do something like package Cachable; use Moose::Role; use MooseX::ClassAttribute; class_has Cache => ( is => 'rw' ); 1; Unfortunately, the code above doesn't work as the deep magic of MooseX::ClassAttribute expects to be called from within a Moose object, and not a Moos...

How come MooseX::Storage doesn't seem to follow attribute traits for some objects?

Hi, I have put together a little test case to demonstrate my problem: package P1; use Moose; use MooseX::Storage; with Storage; has 'blah' => ( is => 'rw', ); package P2; use Moose; use MooseX::Storage; with Storage; has 'lol' => ( is => 'rw', traits => ['DoNotSerialize'] ); package P3; use Moose; extends 'P2'; has 'ma...

Moose or Meta?

I've been trying to do this a number of ways, but none of them seem graceful enough. (I'm also wondering if CPAN or Moose already has this. The dozens of searches I've done over time have shown nothing that quite matches.) I want to create a type of class that is a Base + Facade + Factory for other classes which load themselves as d...

How do you create subtypes in Moose?

Hi, I'm just starting to use Moose. I'm creating a simple notification object and would like to check inputs are of an 'Email' type. (Ignore for now the simple regex match). From the documentation I believe it should look like the following code: # --- contents of message.pl --- # package Message; use Moose; subtype 'Email' => as 'S...

What do you think of MooseX::Declare?

I've stumbled upon the MooseX::Declare documentation, and I have to say "WOW!". That looks really nice! I think it's the cleanest OOP syntax Perl has. use MooseX::Declare; class BankAccount { has 'balance' => ( isa => 'Num', is => 'rw', default => 0 ); method deposit (Num $amount) { $self->balance( $self->balance + $a...

Should I learn Perl 5 OO or Moose first?

I'm still relatively new to Perl Programming, but I know how Perl 5 OO basically works. However, I have never created any project with Perl 5 OO, so I'm quite sure I will run into many pitfalls. Recently I discovered the hype about the Moose module. I checked out some documentation on CPAN and I found it to be quite interesting and help...

What is the best way to create a class attribute in Moose?

I need a class attribute in Moose. Right now I am saying: #!/usr/bin/perl use 5.010; use strict; use warnings; use MooseX::Declare; class User { has id => (isa => "Str", is => 'ro', builder => '_get_id'); has name => (isa => "Str", is => 'ro'); has balance => (isa => "Num", is => 'rw', default => 0); #FIXME: ...

Dealing with multiple-inherited constructors in Moose

Greetings, I'm learning Moose and I'm trying to write a CGI::Application subclass with Moose, which is made difficult by the fact that CGI-App is not based on Moose. In my other CGI-App subclasses, I like to have a parent class with a setup method that looks at the child class's symbol table and automatically sets up the runmodes. I f...

Turning off inline constructors with MooseX::Declare

Greetings, As a followup to my previous question about Moose, I've now run into a new problem. I've got a Moose class which uses Recipe 12 in order to extend a non-Moose parent class. Here it is: package MyApp::CGI; ### TODO: make this work with MooseX::Declare? use Moose; extends 'CGI::Application'; sub new { my $class = shif...

How do Roles and Traits differ in Moose?

I have written a set of classes and interfaces that are implemented in Moose also using roles. What I am having trouble understanding is the exact differences in both usage and implementation of Moose traits vs. roles. The Moose documentation states: It is important to understand that roles and traits are the same thing. A role can ...

How do I declare that a class uses more than one role with MooseX::Declare?

Given that the roles Fooable and Barable have both been defined, how do I say that class FooBar does Fooable and Barable? I have no problem saying #!/usr/bin/perl use MooseX::Declare; role Fooable { method foo { print "foo\n" } } role Barable { method bar { print "bar\n" } } class Foo with Fooable {} class Bar with Barable ...