1MakeMethods::Composite:U:sUenrivCeornstarli(b3u)ted PerlMaDkoecMuemtehnotdast:i:oCnomposite::Universal(3)
2
3
4

NAME

6       Class::MakeMethods::Composite::Universal - Composite Method Tricks
7

SYNOPSIS

9         Class::MakeMethods::Composite::Universal->make_patch(
10           -TargetClass => 'SomeClass::OverYonder',
11           name => 'foo',
12           pre_rules => [
13             sub {
14               my $method = pop;
15               warn "Arguments for foo:", @_
16             }
17           ]
18           post_rules => [
19             sub {
20               warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
21             }
22           ]
23         );
24

DESCRIPTION

26       The Composite::Universal suclass of MakeMethods provides some gener‐
27       ally-applicable types of methods based on Class::MakeMethods::Compos‐
28       ite.
29

METHOD GENERATOR TYPES

31       patch
32
33       The patch ruleset generates composites whose core behavior is based on
34       an existing subroutine.
35
36       Here's a sample usage:
37
38         sub foo {
39           my $count = shift;
40           return 'foo' x $count;
41         }
42
43         Class::MakeMethods::Composite::Universal->make(
44           -ForceInstall => 1,
45           patch => {
46             name => 'foo',
47             pre_rules => [
48               sub {
49                 my $method = pop @_;
50                 if ( ! scalar @_ ) {
51                   @{ $method->{args} } = ( 2 );
52                 }
53               },
54               sub {
55                 my $method = pop @_;
56                 my $count = shift;
57                 if ( $count > 99 ) {
58                   Carp::confess "Won't foo '$count' -- that's too many!"
59                 }
60               },
61             ],
62             post_rules => [
63               sub {
64                 my $method = pop @_;
65                 if ( ref $method->{result} eq 'SCALAR' ) {
66                   ${ $method->{result} } =~ s/oof/oozle-f/g;
67                 } elsif ( ref $method->{result} eq 'ARRAY' ) {
68                   map { s/oof/oozle-f/g } @{ $method->{result} };
69                 }
70               }
71             ],
72           },
73         );
74
75       make_patch
76
77       A convenient wrapper for "make()" and the "patch" method generator.
78
79       Provides the '-ForceInstall' flag, which is required to ensure that the
80       patched subroutine replaces the original.
81
82       For example, one could add logging to an existing method as follows:
83
84         Class::MakeMethods::Composite::Universal->make_patch(
85           -TargetClass => 'SomeClass::OverYonder',
86           name => 'foo',
87           pre_rules => [
88             sub {
89               my $method = pop;
90               warn "Arguments for foo:", @_
91             }
92           ]
93           post_rules => [
94             sub {
95               warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
96             }
97           ]
98         );
99

SEE ALSO

101       See Class::MakeMethods for general information about this distribution.
102
103       See Class::MakeMethods::Composite for more about this family of sub‐
104       classes.
105
106
107
108perl v5.8.8                       2004-09-0M6akeMethods::Composite::Universal(3)
Impressum