MakeMe...iversal(3pm)
π NAME π
okay bestie, this is the MakeMe...iversal(3pm) page for Class::MakeMethods::Composite::Universal β aka Composite Method Tricks. It's part of the User Contributed Perl Documentation, and it's here to hand you some composite method magic β¨
β¨ SYNOPSIS β¨
Class::MakeMethods::Composite::Universal->make_patch(
-TargetClass => 'SomeClass::OverYonder',
name => 'foo',
pre_rules => [
sub {
my $method = pop;
warn "Arguments for foo:", @_
}
]
post_rules => [
sub {
warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
}
]
);
π¦ DESCRIPTION π¦
The Composite::Universal subclass of MakeMethods gives you some generally-applicable types of methods based on Class::MakeMethods::Composite. It's giving "reusable composite method tricks" and honestly? iconic π
π METHOD GENERATOR TYPES π
π patch π
The patch ruleset generates composites whose core behavior is based on an existing subroutine. So yeah, it wraps around something already there and makes it do a little extra π
Here's a sample usage:
sub foo {
my $count = shift;
return 'foo' x $count;
}
Class::MakeMethods::Composite::Universal->make(
-ForceInstall => 1,
patch => {
name => 'foo',
pre_rules => [
sub {
my $method = pop @_;
if ( ! scalar @_ ) {
@{ $method->{args} } = ( 2 );
}
},
sub {
my $method = pop @_;
my $count = shift;
if ( $count > 99 ) {
Carp::confess "Won't foo '$count' -- that's too many!"
}
},
],
post_rules => [
sub {
my $method = pop @_;
if ( ref $method->{result} eq 'SCALAR' ) {
${ $method->{result} } =~ s/oof/oozle-f/g;
} elsif ( ref $method->{result} eq 'ARRAY' ) {
map { s/oof/oozle-f/g } @{ $method->{result} };
}
}
],
},
);
πΈ make_patch πΈ
A convenient wrapper for make() and the patch method generator. It's literally the shortcut bestie π«Ά
It provides the -ForceInstall flag, which is required to ensure that the patched subroutine replaces the original.
bestie, this flag is not optional vibes β -ForceInstall is required here so the patched subroutine actually replaces the original. no cap π
For example, one could add logging to an existing method as follows:
Class::MakeMethods::Composite::Universal->make_patch(
-TargetClass => 'SomeClass::OverYonder',
name => 'foo',
pre_rules => [
sub {
my $method = pop;
warn "Arguments for foo:", @_
}
]
post_rules => [
sub {
warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
}
]
);
π SEE ALSO π
- See
Class::MakeMethodsfor general information about this distribution. β¨ - See
Class::MakeMethods::Compositefor more about this family of subclasses. π¦
mwah π β this page comes from perl v5.36.0, dated 2022-10-13, and its manual name is MakeMe...iversal(3pm). slay, bye ππ
π¦ where this page comes from
- ubuntu noble: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms