NAME
Function::Return::Meta - handle subroutine return types
SYNOPSIS
use Function::Return;
use Function::Return::Meta;
use Types::Standard -types;
sub foo :Return(Int) { 123 }
sub bar { }
my $meta = Function::Return::Meta->get(\&foo);
my $wrapped = Function::Return::Meta->wrap_sub(\&bar, [Str]);
$wrapped->();
CLASS METHODS
get($coderef)
This method lets you introspect return values:
use Function::Return;
use Function::Return::Meta;
use Types::Standard -types;
sub baz() :Return(Str) { 'hello' }
my $meta = Function::Return::Meta->get(\&baz); # Sub::Meta
$meta->returns->list; # [Str]
In addition, it can be used with Function::Parameters:
use Function::Parameters;
use Function::Return;
use Function::Return::Meta;
use Types::Standard -types;
fun hello(Str $msg) :Return(Str) { 'hello' . $msg }
my $meta = Function::Return::Meta->get(\&hello); # Sub::Meta
$meta->returns->list; # [Str]
$meta->args->[0]->type; # Str
$meta->args->[0]->name; # $msg
# Note
Function::Parameters::info \&hello; # undef
This makes it possible to know both type information of function arguments and return value at compile time, making it easier to use for testing etc.
wrap_sub($coderef)
This interface is for power-user. Rather than using the :Return
attribute, it's possible to wrap a coderef like this:
my $wrapped = Function::Return->wrap_sub($orig, [Str]);
$wrapped->();
LICENSE
Copyright (C) kfly8.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
kfly8 <kfly@cpan.org>