Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

object system with chained mutators?

by metaperl (Curate)
on Feb 12, 2009 at 14:53 UTC ( [id://743330]=perlquestion: print w/replies, xml ) Need Help??

metaperl has asked for the wisdom of the Perl Monks concerning the following question:

Since chained mutators are not likely/easy/robust in Moose, I need to find a similar tool which does support things like below:
use Mouse; has 'body' => (is => 'rw'); has 'hdr' => (is => 'rw'); has 'ftr' => (is => 'rw'); 1; my $m = Doc->new; $m->body('double')->hdr->('headless')->ftr('soccer');
It appears that Fey has some technology like this under the hood based on the synopsis example:
$select->select( $user->columns( 'user_id', 'username' ) ) ->from( $user, $group ) ->where( $group->group_id, 'IN', 1, 2, 3 ) ->and ( $func, 'LIKE', 'smith%' );

Replies are listed 'Best First'.
Re: object system with chained mutators?
by Corion (Patriarch) on Feb 12, 2009 at 14:58 UTC

    If Fey does what you want, why don't you take the relevant code out and use it?

    Maybe look at the source of Fey::SQL::Select, which implements the stuff. Basically, it's just not a Moose thing but implemented as routines that do stuff and then return $self. Certainly not rocket surgery.

      I would prefer something on CPAN with a history of popular use.
        Then contribute to Moose. stvn would love for someone to add that MooseX package.

        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: object system with chained mutators?
by Arunbear (Prior) on Feb 12, 2009 at 16:00 UTC
    From the synopsis of Class::Accessor::Chained :
    package Foo; use base qw( Class::Accessor::Chained ); __PACKAGE__->mk_accessors(qw( foo bar baz )); my $foo = Foo->new->foo(1)->bar(2)->baz(4); print $foo->bar; # prints 2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://743330]
Approved by Sinistral
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found