Kenichi Ishigaki > Class-Accessor-Fluent-0.02 > Class::Accessor::Fluent

Download:
Class-Accessor-Fluent-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.02   Source  

NAME ^

Class::Accessor::Fluent - do you like fluent interface?

SYNOPSIS ^

  in your class:

    package MyApp;
    use base qw(Class::Accessor::Fluent);

    __PACKAGE__->mk_fluent_accessors(qw( foo bar ));

    sub do_something {
      my $self = shift;

      print $self->foo, "\n", $self->bar, "\n";
    }

    1;

  then:

    #!perl
    my $app = MyApp->new;
       $app->foo('foo')->bar('bar')->do_something;

  actually you can omit ->new:

    MyApp->foo('foo')->bar('bar')->do_something;

  (you may need extra parentheses to modify the precedence, though)

  run it:

    > myapp.pl
    foo
    bar

  note that you can't set undeclared key/value combos:

    my $app = MyApp->new( not_allowed => 1 );  # croaks
    my $app = MyApp->new;
       $app->{not_allowed} = 1;  # croaks

  so you should always use set/get values via accessors/mutators.

  see the point?

DESCRIPTION ^

This class is to implement so-called "fluent interface" (well, kind of). This is not so cool and useful way of setting options for perl but anyway, there's no accounting for taste :)

CLASS METHODS ^

mk_fluent_accessors

Takes the names of fluent accessors and creates/export them into the caller package.

new

basic constructor that generates a hash based object.

SEE ALSO ^

Class::Accessor::Fast,

Class::Accessor::Chained,

http://d.hatena.ne.jp/antipop/20080710/1215626395 (Japanese blog entry)

AUTHOR ^

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2008 by Kenichi Ishigaki.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.