File Coverage

blib/lib/autobox/Closure/Attributes.pm
Criterion Covered Total %
statement 29 29 100.0
branch 12 12 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod n/a
total 50 50 100.0


line stmt bran cond sub pod time code
1             package autobox::Closure::Attributes;
2 7     7   193420 use strict;
  7         16  
  7         266  
3 7     7   38 use warnings;
  7         15  
  7         207  
4 7     7   46 use base 'autobox';
  7         8  
  7         9727  
5             our $VERSION = '0.04';
6              
7             sub import {
8 7     7   120 shift->SUPER::import(CODE => 'autobox::Closure::Attributes::Methods');
9             }
10              
11             package autobox::Closure::Attributes::Methods;
12 7     7   568146 use PadWalker;
  7         7500  
  7         2401  
13              
14             sub AUTOLOAD {
15 55     55   3765 my $code = shift;
16 55         316 (my $attr = our $AUTOLOAD) =~ s/.*:://;
17              
18             # we want the scalar unless the method name already a sigil
19 55 100       227 $attr = "\$$attr" unless $attr =~ /^[\$\@\%\&\*]/;
20              
21 55         261 my $closed_over = PadWalker::closed_over($code);
22 55 100       241 exists $closed_over->{$attr}
23             or Carp::croak "$code does not close over $attr";
24              
25 51         103 my $ref = ref $closed_over->{$attr};
26              
27 51 100       133 if (@_) {
28 8 100       31 return @{ $closed_over->{$attr} } = @_ if $ref eq 'ARRAY';
  1         6  
29 7 100       24 return %{ $closed_over->{$attr} } = @_ if $ref eq 'HASH';
  1         6  
30 6         12 return ${ $closed_over->{$attr} } = shift;
  6         35  
31             }
32              
33 43 100 100     275 return $closed_over->{$attr} if $ref eq 'HASH' || $ref eq 'ARRAY';
34 29         47 return ${ $closed_over->{$attr} };
  29         208  
35             }
36              
37             1;
38              
39             __END__