File Coverage

blib/lib/PerlX/Perform.pm
Criterion Covered Total %
statement 50 51 98.0
branch 15 16 93.7
condition 16 23 69.5
subroutine 10 10 100.0
pod 3 3 100.0
total 94 103 91.2


line stmt bran cond sub pod time code
1             package PerlX::Perform;
2              
3 3     3   75440 use 5.006;
  3         12  
  3         122  
4 3     3   17 use strict;
  3         6  
  3         545  
5              
6             our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS, @ISA);
7             BEGIN {
8 3     3   7 $PerlX::Perform::AUTHORITY = 'cpan:TOBYINK';
9 3         10 $PerlX::Perform::VERSION = '0.005';
10            
11 3         15 require Exporter;
12 3         44 @ISA = qw/Exporter/;
13 3         8 @EXPORT = qw/perform wherever/;
14 3         21 @EXPORT_OK = qw/perform wherever whenever/;
15 3         1359 %EXPORT_TAGS = (
16             default => \@EXPORT,
17             all => \@EXPORT_OK,
18             wherever => [qw/perform wherever/],
19             whenever => [qw/perform whenever/],
20             );
21             }
22              
23             sub blessed ($)
24             {
25 30     30 1 34 my $thing = shift;
26 30 100 66     212 if (ref $thing and UNIVERSAL::can($thing, 'can'))
27             {
28 10   50     91 return (ref($thing) || $thing || 1);
29             }
30 20         79 return;
31             }
32              
33             sub perform (&;$)
34             {
35 30     30 1 61 my ($coderef, $thing) = @_;
36 30 100       66 if (defined $thing)
37             {
38 12         14 $_ = $thing;
39 12         30 @_ = ();
40 12         30 goto $coderef;
41             }
42 18 100       42 if (@_ == 1)
43             {
44 16         51 return PerlX::Perform::Manifesto->new($coderef);
45             }
46 2         5 return;
47             }
48              
49             sub wherever ($;@)
50             {
51 26     26 1 37 my $thing = shift;
52 26 100 100     115 if (@_ and !ref $_[0] and $_[0] eq 'perform')
      66        
53             {
54 4         6 shift;
55             }
56 26 100 100     98 if (@_ and blessed $_[0] and $_[0]->isa('PerlX::Perform::Manifesto'))
    100 66        
      66        
57             {
58 10         13 my $manifesto = shift;
59 10         21 @_ = ($thing);
60 10         19 goto $manifesto;
61             }
62             elsif (@_ and ref $_[0] eq 'CODE')
63             {
64 4         20 my $manifesto = &perform(shift);
65 4         10 @_ = ($thing);
66 4         8 goto $manifesto;
67             }
68 12         48 return $thing;
69             }
70              
71             *whenever = \&wherever;
72              
73             package PerlX::Perform::Manifesto;
74              
75 3     3   48 use 5.006;
  3         10  
  3         125  
76 3     3   15 use strict;
  3         6  
  3         476  
77              
78             sub new
79             {
80 16     16   25 my ($class, $code) = @_;
81            
82 16 50 33     33 if (PerlX::Perform::blessed $code and $code->isa(__PACKAGE__))
83             {
84 0         0 return $code;
85             }
86            
87             bless sub {
88 14     14   16 my $thing = shift;
89 14 100       39 return unless defined $thing;
90 8         10 $_ = $thing;
91 8         9 @_ = ();
92 8         21 goto $code;
93 16         101 }, $class;
94             }
95              
96             __FILE__
97             __END__