Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

object system with chained mutators?

by metaperl (Curate)
on Feb 12, 2009 at 14:53 UTC ( #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 (Pope) 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 (Parson) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://743330]
Approved by Sinistral
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-12-14 03:03 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (384 votes). Check out past polls.