Data::...odProxy(3pm)
π Data::MethodProxy β the manual, but make it make sense π
okay bestie, welcome to Data::MethodProxy, part of the User Contributed Perl Documentation situation. grab a boba, we're injecting dynamic data into static data and it's genuinely so cute π
β¨ NAME β¨
Data::MethodProxy β inject dynamic data into static data. yes that's the whole name, yes it slays π
πΈ SYNOPSIS πΈ
use Data::MethodProxy;
my $mproxy = Data::MethodProxy->new();
my $output = $mproxy->render({
half_six => ['$proxy', 'main', 'half', 6],
});
# { half_six => 3 }
sub half {
my ($class, $number) = @_;
return $number / 2;
}
see how half_six just became 3? that's the whole vibe. main character energy fr fr π
π¦ DESCRIPTION π¦
okay so a method proxy is an array ref that describes a class method to call, plus the args you wanna pass it. it's giving "a little note that says call this for me".
the first value in that array ref is the scalar $proxy, then a package name, then a subroutine name (which must be callable in that package), and then a list of any subroutine arguments.
[ '$proxy', 'Foo::Bar', 'baz', 123, 4 ]
and that little guy is literally saying: do this.
Foo::Bar->baz( 123, 4 );
the render method is THE main entry point, bestie. it goes through an arbitrary data structure, finds every method proxy, and swaps each one out for the return value of calling the method. obsessed. π
π Example π
picture this static YAML config, no cap:
---
db:
dsn: DBI:mysql:database=foo
username: bar
password: abc123
ngl, putting your database password inside a config file is usually considered a bad practice π (like, girl, no). you can use a method proxy to get around that without jumping through a bunch of hoops:
---
db:
dsn: DBI:mysql:database=foo
username: bar
password:
- $proxy
- MyApp::Config
- get_db_password
- foo-bar
when render gets called on that data structure above, it will see the method proxy and replace the array ref with the return value of calling the method. it's that simple, periodt β¨
a method proxy, in Perl syntax, looks like this:
['$proxy', $package, $method, @args]
and fun fact: the $proxy string can also be written as &proxy. either way, the above gets converted into a method call and replaced by the return value of that method call:
$package->$method( @args );
so in the database password example, the method call would be this:
MyApp::Config->get_db_password( 'foo-bar' );
and yes β you'd still need to actually create a MyApp::Config package, and add a get_db_password method to it. the proxy isn't doing magic, she's just doing the calling. π
π METHODS π
π render
my $output = $mproxy->render( $input );
traverses the supplied data looking for method proxies, calls them, and replaces them with the return value of the method call. you can pass literally any value β a hash ref, an array ref, a method proxy, an object, a scalar, whatever. array and hash refs will be recursively searched for method proxies. she's thorough. she's iconic. π«Ά
β οΈ if a circular reference is detected, an error will be thrown. so like, don't do that. π
π call
my $return = $mproxy->call( ['$proxy', $package, $method, @args] );
calls the method proxy and returns its return. one job, done flawlessly. β¨
π is_valid
die unless $mproxy->is_valid( ... );
returns true if the passed value looks like a method proxy. vibe check complete. β
π is_callable
die unless $mproxy->is_callable( ... );
returns true if the passed value looks like a method proxy and has a package and method which exist. so this one is the stricter bestie β she checks the receipts. π
π SUPPORT π
please submit bugs and feature requests to the Data-MethodProxy GitHub issue tracker:
https://github.com/bluefeet/Data-MethodProxy/issues
πΈ ACKNOWLEDGEMENTS πΈ
thanks to ZipRecruiter https://www.ziprecruiter.com/ for encouraging their employees to contribute back to the open source ecosystem. without their dedication to quality software development this distribution would not exist. genuinely so sweet of them, we love a supportive workplace π
π AUTHORS π
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. free as in, go off, do your thing. π
and that's the whole page bestie!! π documented by the User Contributed Perl Documentation girlies, running on perl v5.40.1, dated 2025-05-04 β mwah, go proxy some methods, ily π π
π¦ where this page comes from
- debian trixie: libdata-methodproxy-perl 0.05-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-methodproxy-perl 0.05-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-methodproxy-perl 0.05-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms