Matthew Simon Cavalletto
Wed, 08 Dec 2004 10:46:54 -0800
On Saturday, December 4, 2004, at 09:18 PM, Terrence Brannon wrote:
A recent contribution to CPAN is Class::MixinFactory by Simon Cavaletto.
Here we show two more ways to do the same thing in addition to the ones
that Simon lists in the SEE ALSO section.
1. Create polymorphic instances, which hide different behaviors behind an identical-looking simple calling interface;
2. Allow behaviors for several functions to be grouped together, so that one user-selectable option can influence multiple methods;
3. Allow behaviors to control how items later in the chain are called, so that they can wrap them in an eval, cache the results, do something before the call and then clean up after, etc.
He also makes mention of a number of other approaches and
perhaps should mention Class::Delegation in addition.
-Simon
----------------------------------------------------------------------
# POST-SCRIPT WITH EXAMPLES
It's easy to construct curried functions:
sub build_func {
my @funcs = @_;
sub {
my $seed = shift;
$seed = $_->( $seed ) foreach ( @funcs );
$seed;
}
}my $viewer_1 = build_func(\&_uc, \&bold, \&italics);
my $viewer_2 = build_func(\&italics, \&bold);
warn $viewer_1->("hello, world!"); sub build_method {
my @methods = @_;
sub {
my ( $self, $seed ) = @_;
$seed = $self->$_( $seed ) foreach ( @methods );
$seed;
}
} my $views = Class::Prototyped->new(
uc_m => sub { uc $_[1] },
italics_m => sub { italics $_[1] },
bold_m => sub { bold $_[1] }
); my $viewer_1 = Class::Prototyped->new(
'*' => $views,
'view' => build_method( qw/ uc_m bold_m italics_m / ),
); my $viewer_2 = Class::Prototyped->new(
'*' => $views,
'view' => build_method( qw/ italics_m bold_m / ),
); warn $viewer_1->view("hello, world!");
_______________________________________________ sw-design mailing list [EMAIL PROTECTED] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design