Skip to content

Commit

Permalink
Merge pull request #5 from bayashi/export-pkg-feature
Browse files Browse the repository at this point in the history
Add import option `pkg`
  • Loading branch information
kfly8 committed Feb 18, 2019
2 parents deb48f3 + 66e310d commit 5b5c65d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Function/Return.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ sub import {
my $class = shift;
my %args = @_;

$pkg = $args{pkg} ? $args{pkg} : $pkg;

$IMPORT{name} = exists $args{name} ? $args{name} : $DEFAULT_ATTR_NAME;
$IMPORT{no_check} = exists $args{no_check} ? $args{no_check} : !!0;

Expand Down Expand Up @@ -255,6 +257,14 @@ you can switch off type check:
sub foo :Return(Int) { 3.14 }
foo(); # NO ERROR!
=head3 pkg
Function::Return automatically exports a return type by caller.
Or you can specify a package name:
use Function::Return pkg => 'MyClass';
=head2 METHODS
=head3 Function::Return::info($coderef)
Expand Down
14 changes: 14 additions & 0 deletions t/06_import_option_pkg.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use strict;
use warnings;
use Test::More;

use Function::Return pkg => 'MyPkg';

is(MyPkg->foo, 123);

done_testing;

package MyPkg;
use Types::Standard 'Int';

sub foo :Return(Int) { 123 }

0 comments on commit 5b5c65d

Please sign in to comment.