1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
package MooX::MethodProxyArgs;
our $VERSION = '0.08';
=encoding utf8
=head1 NAME
MooX::MethodProxyArgs - Invoke code to populate static arguments.
=head1 SYNOPSIS
package Foo;
use Moo;
with 'MooX::MethodProxyArgs';
has bar => (
is => 'ro',
);
package main;
sub divide {
my ($class, $number, $divisor) = @_;
return $number / $divisor;
}
my $foo = Foo->new( bar => ['$proxy', 'main', 'divide', 10, 2 ] );
print $foo->bar(); # 5
=head1 DESCRIPTION
This module munges the class's input arguments by replacing any
method proxy values found with the result of calling the methods.
This is done using L<Data::MethodProxy>. See that module for more
information on how method proxies work.
=cut
use Data::MethodProxy;
use Moo::Role;
use strictures 2;
use namespace::clean;
with 'MooX::BuildArgsHooks';
my $mproxy = Data::MethodProxy->new();
around TRANSFORM_BUILDARGS => sub{
my ($orig, $class, $args) = @_;
$args = $class->TRANSFORM_METHOD_PROXY_ARGS_BUILDARGS( $args );
return $class->$orig( $args );
};
sub TRANSFORM_METHOD_PROXY_ARGS_BUILDARGS {
my ($class, $args) = @_;
return $mproxy->render( $args );
}
1;
__END__
=head1 SEE ALSO
=over
=item *
L<MooX::BuildArgs>
=item *
L<MooX::BuildArgsHooks>
=item *
L<MooX::Rebuild>
=item *
L<MooX::SingleArg>
=back
=head1 SUPPORT
See L<MooX::BuildArgs/SUPPORT>.
=head1 AUTHORS
See L<MooX::BuildArgs/AUTHORS>.
=head1 LICENSE
See L<MooX::BuildArgs/LICENSE>.
=cut
|