File Coverage

blib/lib/Sub/ArgShortcut.pm
Criterion Covered Total %
statement 24 26 92.3
branch 9 10 90.0
condition n/a
subroutine 7 8 87.5
pod 1 2 50.0
total 41 46 89.1


line stmt bran cond sub pod time code
1 2     2   21735 use 5.006;
  2         5  
  2         71  
2 2     2   10 use strict;
  2         3  
  2         60  
3 2     2   8 use warnings;
  2         2  
  2         413  
4              
5             package Sub::ArgShortcut;
6             $Sub::ArgShortcut::VERSION = '1.021';
7             # ABSTRACT: simplify writing functions that use default arguments
8              
9 0     0 0 0 sub croak { require Carp; goto &Carp::croak }
  0         0  
10              
11             sub argshortcut(&) {
12 2     2 1 13 my ( $code ) = @_;
13             return sub {
14 8     8   3738 my @byval;
15 8         13 my $nondestructive = defined wantarray;
16 8 100       49 $code->(
    100          
    100          
17             $nondestructive
18             ? ( @byval = @_ ? @_ : $_ )
19             : ( @_ ? @_ : $_ )
20             );
21 8 100       76 return $nondestructive ? @byval[ 0 .. $#byval ] : ();
22 2         18 };
23             }
24              
25             sub import {
26 2     2   9 my $class = shift;
27 2         10 my $install_pkg = caller;
28 2 50       9 die q(Something mysterious happened) if not defined $install_pkg;
29 2     2   14 { no strict 'refs'; *{"${install_pkg}::argshortcut"} = \&argshortcut; }
  2         4  
  2         172  
  2         2  
  2         4  
  2         1575  
30             }
31              
32             1;
33              
34             __END__