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
27       generally-applicable types of methods based on
28       Class::MakeMethods::Composite.
29

METHOD GENERATOR TYPES

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

SEE ALSO

99       See Class::MakeMethods for general information about this distribution.
100
101       See Class::MakeMethods::Composite for more about this family of
102       subclasses.
103
104
105
106perl v5.32.0                      2020-07-2M8akeMethods::Composite::Universal(3)
Impressum