File Coverage

blib/lib/Lexical/Context.pm
Criterion Covered Total %
statement 35 38 92.1
branch 6 10 60.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 0 2 0.0
total 50 60 83.3


line stmt bran cond sub pod time code
1             package Lexical::Context;
2              
3 1     1   5 use strictures 2;
  1         4  
  1         47  
4 1     1   194 use B qw(svref_2object);
  1         3  
  1         74  
5 1     1   369 use Moo;
  1         9665  
  1         6  
6              
7             has code => (is => 'ro', required => 1);
8              
9             has _pad_indices => (is => 'lazy', builder => sub {
10 1     1   11 my ($self) = @_;
11 1         22 my @b_pn = svref_2object($self->code)->PADLIST->ARRAYelt(0)->ARRAY;
12             return +{
13             map +($b_pn[$_]->PV => $_),
14             grep {
15 1         4 my $b_pn = $b_pn[$_];
  8         12  
16 8 50       21 $b_pn->can('PV') and do {
17 8         12 my $pn = $b_pn->PV;
18 8 100 66     46 defined($pn) and length($pn) and $pn ne '&'
19             };
20             } 0..$#b_pn
21             };
22             });
23              
24             sub _current_pad {
25 12     12   16 my ($self) = @_;
26 12         86 return (svref_2object($self->code)->PADLIST->ARRAY)[-1]->ARRAY;
27             }
28              
29             sub get_pad_values {
30 6     6 0 9 my ($self) = @_;
31 6         91 my $pad_indices = $self->_pad_indices;
32 6         34 my @curpad = $self->_current_pad;
33             return +{
34 6         76 map +($_ => $curpad[$pad_indices->{$_}]->object_2svref),
35             keys %$pad_indices
36             };
37             }
38              
39             sub set_pad_values {
40 6     6 0 9 my ($self, $new_values) = @_;
41 6         95 my $pad_indices = $self->_pad_indices;
42 6         38 my @curpad = $self->_current_pad;
43 6         21 foreach my $name (keys %$new_values) {
44 18         34 my $pad_value = $curpad[$pad_indices->{$name}]->object_2svref;
45 18 100       50 if ($name =~ /^\$/) {
    50          
    0          
46 12         14 ${$pad_value} = ${$new_values->{$name}};
  12         20  
  12         17  
47             } elsif ($name =~ /^\@/) {
48 6         7 @{$pad_value} = @{$new_values->{$name}};
  6         16  
  6         14  
49             } elsif ($name =~ /^\%/) {
50 0         0 %{$pad_value} = %{$new_values->{$name}};
  0         0  
  0         0  
51             }
52             }
53 6         15 return;
54             }
55              
56             1;