NAME

MooX::MethodProxyArgs - Invoke code to populate static arguments.

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

DESCRIPTION

This module munges the class's input arugments by replacing any method proxy values found with the result of calling the methods.

A method proxy looks like this:

[ '&proxy', $package, $sub_name, @args ]

When any argument's value is an array ref, where the first value in the array ref is the string &proxy, then it will be considered to be a method proxy and the value will be replaced with whatever value is returned from calling:

$package->$sub_name( @args );

When your objects support method proxies it can make it much easier for users of your objects to assign dynamic values to arguments from static configuration sources, such as configuration files.

SEE ALSO

AUTHOR

Aran Clary Deltac <bluefeet@gmail.com>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.