DCI::Meta::Context - Primary Interface, and metadata object for Context classes.
This is the Meta object for building Context objects.
package Test::Context; use strict; use warnings; use DCI::Meta::Context; # roles to fill that have no cast type casting qw/middle/; # roles to fill with existing casts cast first => 'Test::Context::First', last => 'Test::Context::Last'; # create a cast on the fly cast punctuation => { delegate => 'text', render => sub { shift->text }, }; # Optional roles (Not used later in this example) maybe_casting qw/tail_a tail_b/; maybe_cast tail_c => 'Test::Context::First', nothing => { delegate => 'text', render => sub { shift->text }, }; ############# # These are various examples of exporting 'sugar' methods that help people # to use your Context. ############# sugar render_named => 'render'; sugar render_custom_named => sub { shift->render }; sugar render_ordered => ( method => 'render', ordered => [qw/first middle last punctuation/], ); sugar render_custom_ordered => ( ordered => [qw/first middle last punctuation/], method => sub { shift->render }, ); sugar render_mixed => ( method => 'render', ordered => [qw/first middle last/] ); # You can define any methods you would like on the context. All roles can # be accessed via method which shares the roles name. sub render { my $self = shift; join( ", ", $self->first->render, $self->middle, $self->last->render, ); }
All exports are optional. This class uses Exporter::Declare for exporting, which means you can use any Exporter::Declare feature such as export renaming.
Defines required roles that must be provided when building an instance of the context. A cast package name must be provided for each role, or undef can be used for no type. When the cast is built the role will be wrapped in the cast type automatically.
Define required roles that do not need to be cast into anything.
Same as cast() except roles are optional at construction.
cast()
Same as casting() except roles are optional at construction.
casting()
Creates an export that will build an instance of your context and then call the specified method. You can also specify an order of arguments so that users do not need to provide role => actor mappings.
sugar render_named => 'render'; # How it is used render_named( first => $first, middle => $middle, last => $last, punctuation => $punctuation, ), sugar render_ordered => ( method => 'render', ordered => [qw/first middle last punctuation/], ); # How it is used render_ordered( $first, $middle, $last, $punctuation ),
Also see DCI::Meta for more methods.
Create a new instance of DCI::Meta::Context.
Target Context package for this instance.
List of required roles.
List of optional roles.
Get a map of export_name => sub containing all sugar methods.
Get the cast type for a specific role.
See the cast(), maybe_cast(), casting(), and maybe_casting exports above.
maybe_cast()
maybe_casting
Add a sugar method to the class (See the sugar() export).
sugar()
Do not use these.
The DCI concept was created by Trygve Reenskaug, (inventor of MVC) and James Coplien.
Chad Granum exodist7@gmail.com
Copyright (C) 2011 Chad Granum
DCI is free software; Standard perl licence.
DCI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
To install DCI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DCI
CPAN shell
perl -MCPAN -e shell install DCI
For more information on module installation, please visit the detailed CPAN module installation guide.