r35346 - in /trunk/libmoosex-role-parameterized-perl: ./ debian/ lib/MooseX/Role/ lib/MooseX/Role/Parameterized/ lib/MooseX/Role/Parameterized/Meta/ lib/MooseX/Role/Parameterized/Meta/Role/ t/

bricas-guest at users.alioth.debian.org bricas-guest at users.alioth.debian.org
Wed May 13 14:19:18 UTC 2009


Author: bricas-guest
Date: Wed May 13 14:19:13 2009
New Revision: 35346

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=35346
Log:
New upstream release

Added:
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pod
Removed:
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pm
Modified:
    trunk/libmoosex-role-parameterized-perl/Changes
    trunk/libmoosex-role-parameterized-perl/MANIFEST
    trunk/libmoosex-role-parameterized-perl/META.yml
    trunk/libmoosex-role-parameterized-perl/Makefile.PL
    trunk/libmoosex-role-parameterized-perl/README
    trunk/libmoosex-role-parameterized-perl/debian/changelog
    trunk/libmoosex-role-parameterized-perl/dist.ini
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized.pm
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Parameter.pm
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm
    trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Parameters.pm
    trunk/libmoosex-role-parameterized-perl/t/150-composite-role-application.t

Modified: trunk/libmoosex-role-parameterized-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/Changes?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/Changes (original)
+++ trunk/libmoosex-role-parameterized-perl/Changes Wed May 13 14:19:13 2009
@@ -1,4 +1,10 @@
 Changes for MooseX-Role-Parameterized
+
+0.06  May 12, 2009
+    * Fix long-standing role-role combination bug, reported by several
+      users (Sartak)
+
+    * Documentation improvements (Sartak)
 
 0.05  Apr 24, 2009
     * Use replace_constructor in Meta::Parameter's make_immutable (nothingmuch)

Modified: trunk/libmoosex-role-parameterized-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/MANIFEST?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/MANIFEST (original)
+++ trunk/libmoosex-role-parameterized-perl/MANIFEST Wed May 13 14:19:13 2009
@@ -10,7 +10,7 @@
 lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm
 lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm
 lib/MooseX/Role/Parameterized/Parameters.pm
-lib/MooseX/Role/Parameterized/Tutorial.pm
+lib/MooseX/Role/Parameterized/Tutorial.pod
 t/001-parameters.t
 t/002-role-block.t
 t/003-apply.t

Modified: trunk/libmoosex-role-parameterized-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/META.yml?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/META.yml (original)
+++ trunk/libmoosex-role-parameterized-perl/META.yml Wed May 13 14:19:13 2009
@@ -6,6 +6,6 @@
 license: perl
 name: MooseX-Role-Parameterized
 requires: 
-  Moose: 0.73
+  Moose: 0.78
   Test::Exception: 0.27
-version: 0.05
+version: 0.06

Modified: trunk/libmoosex-role-parameterized-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/Makefile.PL?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/Makefile.PL (original)
+++ trunk/libmoosex-role-parameterized-perl/Makefile.PL Wed May 13 14:19:13 2009
@@ -9,11 +9,11 @@
   NAME      => 'MooseX::Role::Parameterized',
   AUTHOR    => 'Shawn\ M\ Moore\ \<sartak\@bestpractical\.com\>',
   ABSTRACT  => 'parameterized roles',
-  VERSION   => '0.05',
+  VERSION   => '0.06',
   EXE_FILES => [ qw() ],
   (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
   PREREQ_PM    => {
     "Test::Exception" => '0.27',
-    "Moose" => '0.73',
+    "Moose" => '0.78',
   },
 );

Modified: trunk/libmoosex-role-parameterized-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/README?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/README (original)
+++ trunk/libmoosex-role-parameterized-perl/README Wed May 13 14:19:13 2009
@@ -1,7 +1,7 @@
 
 
 This archive contains the distribution MooseX-Role-Parameterized, version
-0.05:
+0.06:
 
   parameterized roles
 

Modified: trunk/libmoosex-role-parameterized-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/debian/changelog?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/debian/changelog (original)
+++ trunk/libmoosex-role-parameterized-perl/debian/changelog Wed May 13 14:19:13 2009
@@ -1,3 +1,9 @@
+libmoosex-role-parameterized-perl (0.06-1) UNRELEASED; urgency=low
+
+  * New upstream release
+
+ -- Brian Cassidy <brian.cassidy at gmail.com>  Wed, 13 May 2009 11:18:38 -0300
+
 libmoosex-role-parameterized-perl (0.05-1) unstable; urgency=low
 
   * Initial Release (Closes: #526687)

Modified: trunk/libmoosex-role-parameterized-perl/dist.ini
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/dist.ini?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/dist.ini (original)
+++ trunk/libmoosex-role-parameterized-perl/dist.ini Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 name    = MooseX-Role-Parameterized
-version = 0.05
+version = 0.06
 author  = Shawn M Moore <sartak at bestpractical.com>
 license = Perl_5
 copyright_holder = Infinity Interactive
@@ -7,6 +7,6 @@
 [@Classic]
 
 [Prereq]
-Moose = 0.73
+Moose = 0.78
 Test::Exception = 0.27
 

Modified: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized.pm?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized.pm (original)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized.pm Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 package MooseX::Role::Parameterized;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 use Moose (
     extends => { -as => 'moose_extends' },
@@ -27,7 +27,7 @@
     confess "'parameter' may not be used inside of the role block"
         if $CURRENT_METACLASS;
 
-    my $meta   = Class::MOP::Class->initialize($caller);
+    my $meta   = Class::MOP::class_of($caller);
 
     my $names = shift;
     $names = [$names] if !ref($names);
@@ -40,7 +40,7 @@
 sub role (&) {
     my $caller         = shift;
     my $role_generator = shift;
-    Class::MOP::Class->initialize($caller)->role_generator($role_generator);
+    Class::MOP::class_of($caller)->role_generator($role_generator);
 }
 
 sub init_meta {
@@ -53,7 +53,7 @@
 
 sub has {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     my $names = shift;
     $names = [$names] if !ref($names);
@@ -65,7 +65,7 @@
 
 sub method {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     my $name   = shift;
     my $body   = shift;
@@ -79,61 +79,46 @@
     $meta->add_method($name => $method);
 }
 
-sub before {
-    my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+sub _add_method_modifier {
+    my $type   = shift;
+    my $caller = shift;
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     my $code = pop @_;
 
     for (@_) {
         Carp::croak "Roles do not currently support "
             . ref($_)
-            . " references for before method modifiers"
+            . " references for $type method modifiers"
             if ref $_;
-        $meta->add_before_method_modifier($_, $code);
+
+        my $add_method = "add_${type}_method_modifier";
+        $meta->$add_method($_, $code);
     }
 }
 
+sub before {
+    _add_method_modifier('before', @_);
+}
+
 sub after {
-    my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
-
-    my $code = pop @_;
-
-    for (@_) {
-        Carp::croak "Roles do not currently support "
-            . ref($_)
-            . " references for after method modifiers"
-            if ref $_;
-        $meta->add_after_method_modifier($_, $code);
-    }
+    _add_method_modifier('after', @_);
 }
 
 sub around {
-    my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
-
-    my $code = pop @_;
-
-    for (@_) {
-        Carp::croak "Roles do not currently support "
-            . ref($_)
-            . " references for around method modifiers"
-            if ref $_;
-        $meta->add_around_method_modifier($_, $code);
-    }
+    _add_method_modifier('around', @_);
 }
 
 sub with {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     Moose::Util::apply_all_roles($meta, @_);
 }
 
 sub requires {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     Carp::croak "Must specify at least one method" unless @_;
     $meta->add_required_methods(@_);
@@ -141,7 +126,7 @@
 
 sub excludes {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     Carp::croak "Must specify at least one role" unless @_;
     $meta->add_excluded_roles(@_);
@@ -155,7 +140,7 @@
 
 sub override {
     my $caller = shift;
-    my $meta   = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller);
+    my $meta   = $CURRENT_METACLASS || Class::MOP::class_of($caller);
 
     my ($name, $code) = @_;
     $meta->add_override_method_modifier($name, $code);
@@ -177,7 +162,7 @@
 
 =head1 VERSION
 
-version 0.05
+version 0.06
 
 =head1 SYNOPSIS
 
@@ -219,29 +204,43 @@
 =head1 L<MooseX::Role::Parameterized::Tutorial>
 
 B<Stop!> If you're new here, please read
-L<MooseX::Role::Parameterized::Tutorial>.
+L<MooseX::Role::Parameterized::Tutorial> for a much gentler introduction.
 
 =head1 DESCRIPTION
 
-Your parameterized role consists of two things: parameter declarations and a
-C<role> block.
+Your parameterized role consists of two new things: parameter declarations
+and a C<role> block.
 
 Parameters are declared using the L</parameter> keyword which very much
 resembles L<Moose/has>. You can use any option that L<Moose/has> accepts. The
-default value for the "is" option is "ro" as that's a very common case. These
+default value for the C<is> option is C<ro> as that's a very common case. These
 parameters will get their values when the consuming class (or role) uses
 L<Moose/with>. A parameter object will be constructed with these values, and
 passed to the C<role> block.
 
 The C<role> block then uses the usual L<Moose::Role> keywords to build up a
 role. You can shift off the parameter object to inspect what the consuming
-class provided as parameters. You can use the parameters to make your role
-customizable!
-
-There are many paths to parameterized roles (hopefully with a consistent enough
-API); I believe this to be the easiest and most flexible implementation.
-Coincidentally, Pugs has a very similar design (I'm not yet convinced that that
-is a good thing).
+class provided as parameters. You use the parameters to customize your
+role however you wish.
+
+There are many possible implementations for parameterized roles (hopefully with
+a consistent enough API); I believe this to be the easiest and most flexible
+design. Coincidentally, Pugs originally had an eerily similar design.
+
+=head2 Why a parameters object?
+
+I've been asked several times "Why use a parameter I<object> and not just a
+parameter I<hashref>? That would eliminate the need to explicitly declare your
+parameters."
+
+The benefits of using an object are similar to the benefits of using Moose. You
+get an easy way to specify lazy defaults, type constraint, delegation, and so
+on. You get to use MooseX modules.
+
+You also get the usual introspective and intercessory abilities that come
+standard with the metaobject protocol. Ambitious users should be able to add
+traits to the parameters metaclass to further customize behavior. Please let
+me know if you're doing anything viciously complicated with this extension. :)
 
 =head1 CAVEATS
 
@@ -251,7 +250,7 @@
 
 L<Moose::Role/alias> and L<Moose::Role/excludes> are not yet supported. I'm
 completely unsure of whether they should be handled by this module. Until we
-figure out a plan, both declaring and providing a parameter named C<alias> or
+figure out a plan, either declaring or providing a parameter named C<alias> or
 C<excludes> is an error.
 
 =head1 AUTHOR
@@ -264,12 +263,14 @@
 
 =item L<MooseX::Role::Matcher>
 
-=item L<MooseX::Role::RelatedClassRoles>
-
 =item L<MooseX::Role::XMLRPC::Client>
 
+=item L<MooseX::RelatedClassRoles>
+
 =item L<WWW::Mechanize::TreeBuilder>
 
+=item L<NetHack::Item::Role::IncorporatesStats>
+
 =item L<TAEB::Action::Role::Item>
 
 =item L<KiokuDB::Role::Scan>

Modified: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Parameter.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Parameter.pm?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Parameter.pm (original)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Parameter.pm Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 package MooseX::Role::Parameterized::Meta::Parameter;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 use Moose;
 extends 'Moose::Meta::Attribute';
@@ -28,3 +28,20 @@
 
 1;
 
+__END__
+
+=head1 NAME
+
+MooseX::Role::Parameterized::Meta::Parameter - metaclass for parameters
+
+=head1 VERSION
+
+version 0.06
+
+=head1 DESCRIPTION
+
+This is the metaclass for parameter objects, a subclass of
+L<Moose::Meta::Attribute>. Its sole purpose is to make the default value
+of the C<is> option C<ro>.
+
+=cut

Modified: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm (original)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 package MooseX::Role::Parameterized::Meta::Role::Parameterizable;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 use Moose;
 extends 'Moose::Meta::Role';
@@ -85,6 +85,15 @@
     return $role;
 }
 
+sub _role_for_combination {
+    my $self = shift;
+    my $parameters = shift;
+
+    return $self->generate_role(
+        parameters => $parameters,
+    );
+}
+
 sub apply {
     my $self     = shift;
     my $consumer = shift;
@@ -117,7 +126,7 @@
 
 =head1 VERSION
 
-version 0.05
+version 0.06
 
 =head1 DESCRIPTION
 

Modified: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm (original)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 package MooseX::Role::Parameterized::Meta::Role::Parameterized;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 use Moose;
 extends 'Moose::Meta::Role';
@@ -24,7 +24,7 @@
 
 =head1 VERSION
 
-version 0.05
+version 0.06
 
 =head1 DESCRIPTION
 

Modified: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Parameters.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Parameters.pm?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Parameters.pm (original)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Parameters.pm Wed May 13 14:19:13 2009
@@ -1,5 +1,5 @@
 package MooseX::Role::Parameterized::Parameters;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 use Moose;
 
@@ -16,7 +16,7 @@
 
 =head1 VERSION
 
-version 0.05
+version 0.06
 
 =head1 DESCRIPTION
 

Added: trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pod
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pod?rev=35346&op=file
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pod (added)
+++ trunk/libmoosex-role-parameterized-perl/lib/MooseX/Role/Parameterized/Tutorial.pod Wed May 13 14:19:13 2009
@@ -1,0 +1,175 @@
+=pod
+
+=head1 NAME
+
+MooseX::Role::Parameterized::Tutorial - why and how
+
+=head1 MOTIVATION
+
+Roles are composable units of behavior. They are useful for factoring out
+functionality common to many classes from any part of your class hierarchy. See
+L<Moose::Cookbook::Roles::Recipe1> for an introduction to L<Moose::Role>.
+
+While combining roles affords you a great deal of flexibility, individual roles
+have very little in the way of configurability. Core Moose provides C<alias>
+for renaming methods and C<excludes> for ignoring methods. These options are
+primarily (perhaps solely) for disambiguating role conflicts. See
+L<Moose::Cookbook::Roles::Recipe2> for more about C<alias> and C<excludes>.
+
+Because roles serve many different masters, they usually provide only the least
+common denominator of functionality. To empower roles further, more
+configurability than C<alias> and C<excludes> is required. Perhaps your role
+needs to know which method to call when it is done. Or what default value to
+use for its C<url> attribute.
+
+Parameterized roles offer exactly this solution.
+
+=head1 USAGE
+
+=head3 C<with>
+
+The syntax of a class consuming a parameterized role has not changed from the
+standard C<with>. You pass in parameters just like you pass in C<alias> and
+C<excludes> to ordinary roles:
+
+    with 'MyRole::InstrumentMethod' => {
+        method_name => 'dbh_do',
+        log_to      => 'query.log',
+    };
+
+You can still combine parameterized roles. You just need to specify parameters
+immediately after the role they belong to:
+
+    with (
+        'My::Parameterized::Role' => {
+            needs_better_example => 1,
+        },
+        'My::Other::Role',
+    );
+
+=head3 C<parameter>
+
+Inside your parameterized role, you specify a set of parameters. This is
+exactly like specifying the attributes of a class. Instead of C<has> you use
+the keyword C<parameter>, but your parameters can use any options to C<has>.
+
+    parameter 'delegation' => (
+        isa       => 'HashRef|ArrayRef|RegexpRef',
+        predicate => 'has_delegation',
+    );
+
+You do have to declare what parameters you accept, just like you have to
+declare what attributes you accept for regular Moose objects.
+
+=head3 C<role>
+
+C<role> takes a block of code that will be used to generate your role with its
+parameters bound. Here is where you declare parameterized components: use
+C<has>, method modifiers, and so on. The C<role> block receives an argument,
+which contains the parameters specified by C<with>. You can access the
+parameters just like regular attributes on that object.
+
+Each time you compose this parameterized role, the role {} block will be
+executed. It will receive a new parameter object and produce an entirely new
+role. That's the whole point, after all.
+
+Due to limitations inherent in Perl, you must declare methods with
+C<< method name => sub { ... } >> instead of the usual C<sub name { ... }>.
+Your methods may, of course, close over the parameter object. This means that
+your methods may use parameters however they wish!
+
+=head1 USES
+
+Ideally these will become fully-explained examples in something resembling
+L<Moose::Cookbook>. But for now, only a braindump.
+
+=over 4
+
+=item Configure a role's attributes
+
+You can rename methods with core Moose, but now you can rename attributes. You
+can now also choose type, default value, whether it's required, B<traits>, etc.
+
+    parameter traits => (
+        isa     => 'ArrayRef[Str]',
+        default => sub { [] },
+    );
+
+    parameter type => (
+        isa     => 'Str',
+        default => 'Any',
+    );
+
+    role {
+        my $p = shift;
+
+        has action => (
+            traits => $p->traits,
+            isa    => $p->type,
+            ...
+        );
+    }
+
+=item Inform a role of your class' attributes and methods
+
+Core roles can require only methods with specific names. Now your roles can
+require that you specify a method name you wish the role to instrument, or
+which attributes to dump to a file.
+
+    parameter instrument_method => (
+        isa      => 'Str',
+        required => 1,
+    );
+
+    role {
+        my $p = shift;
+        around $p->instrument_method => sub { ... };
+    }
+
+=item Arbitrary execution choices
+
+Your role may be able to provide configuration in how the role's methods
+operate. For example, you can tell the role whether to save intermediate
+states.
+
+    parameter save_intermediate => (
+        isa     => 'Bool',
+        default => 0,
+    );
+
+    role {
+        my $p = shift;
+        method process => sub {
+            ...
+            if ($p->save_intermediate) { ... }
+            ...
+        };
+    }
+
+=item Deciding a backend
+
+Your role may be able to freeze and thaw your instances using L<YAML>, L<JSON>,
+L<Storable>. Which backend to use can be a parameter.
+
+    parameter format => (
+        isa     => (enum ['Storable', 'YAML', 'JSON']),
+        default => 'Storable',
+    );
+
+    role {
+        my $p = shift;
+        if ($p->format eq 'Storable') {
+            method freeze => \&Storable::freeze;
+            method thaw   => \&Storable::thaw;
+        }
+        elsif ($p->format eq 'YAML') {
+            method freeze => \&YAML::Dump;
+            method thaw   => \&YAML::Load;
+        }
+        ...
+    }
+
+=back
+
+=cut
+

Modified: trunk/libmoosex-role-parameterized-perl/t/150-composite-role-application.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libmoosex-role-parameterized-perl/t/150-composite-role-application.t?rev=35346&op=diff
==============================================================================
--- trunk/libmoosex-role-parameterized-perl/t/150-composite-role-application.t (original)
+++ trunk/libmoosex-role-parameterized-perl/t/150-composite-role-application.t Wed May 13 14:19:13 2009
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 use Test::Exception;
 
 do {
@@ -18,7 +18,7 @@
         my $p = shift;
 
         has $p->attribute => (
-            is => 'Int',
+            is => 'rw',
         );
     };
 };
@@ -49,11 +49,8 @@
          MyCompositeRoleB => { accessor  => 'bar' };
 };
 
-TODO: {
-    local $TODO = "role-role application for parameterized roles doesn't work yet";
-    ok(MyDoubleConsumer->can('foo'), 'first role in composite applied successfully');
-    ok(MyDoubleConsumer->can('bar'), 'second role in composite applied successfully');
-};
+ok(MyDoubleConsumer->can('foo'), 'first role in composite applied successfully');
+ok(MyDoubleConsumer->can('bar'), 'second role in composite applied successfully');
 
 do {
     package MyExtendingRole;
@@ -78,15 +75,13 @@
 do {
     package MyExtendedConsumer;
     use Moose;
-    with MyCompositeRoleA => { attribute => 'bar' },
+    with MyCompositeRoleA => { attribute => 'baz' },
          MyExtendingRole  => { foo => 23 };
 };
 
-TODO: {
-    local $TODO = "role-role application for parameterized roles doesn't work yet";
-    ok(MyExtendedConsumer->can('bar'), 'role composed through other role applied successfully');
-    is(eval { MyExtendedConsumer->new->foo }, 23, 'role composing other role applied successfully');
-};;
+ok(MyExtendedConsumer->can('baz'), 'role composed directly applied successfully');
+ok(MyExtendedConsumer->can('bar'), 'role composed through other role applied successfully');
+is(eval { MyExtendedConsumer->new->foo }, 23, 'role composing other role applied successfully');
 
 do {
     package MyRoleProxy;
@@ -116,9 +111,6 @@
     );
 };
 
-TODO: {
-    local $TODO = "role-role application for parameterized roles doesn't work yet";
-    ok(MyProxyConsumer->can('baz'), 'proxied role got applied successfully');
-    ok(MyProxyConsumer->can('qux'), 'other role besides proxied one got applied successfully');
-};
+ok(MyProxyConsumer->can('baz'), 'proxied role got applied successfully');
+ok(MyProxyConsumer->can('qux'), 'other role besides proxied one got applied successfully');
 




More information about the Pkg-perl-cvs-commits mailing list