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   7 use strictures 2;
  1         5  
  1         40  
4 1     1   136 use B qw(svref_2object);
  1         2  
  1         69  
5 1     1   432 use Moo;
  1         10277  
  1         7  
6              
7             has code => (is => 'ro', required => 1);
8              
9             has _pad_indices => (is => 'lazy', builder => sub {
10 1     1   9 my ($self) = @_;
11 1         18 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       32 $b_pn->can('PV') and do {
17 8         15 my $pn = $b_pn->PV;
18 8 100 66     51 defined($pn) and length($pn) and $pn ne '&'
19             };
20             } 0..$#b_pn
21             };
22             });
23              
24             sub _current_pad {
25 12     12   20 my ($self) = @_;
26 12         78 return (svref_2object($self->code)->PADLIST->ARRAY)[-1]->ARRAY;
27             }
28              
29             sub get_pad_values {
30 6     6 0 7 my ($self) = @_;
31 6         96 my $pad_indices = $self->_pad_indices;
32 6         35 my @curpad = $self->_current_pad;
33             return +{
34 6         80 map +($_ => $curpad[$pad_indices->{$_}]->object_2svref),
35             keys %$pad_indices
36             };
37             }
38              
39             sub set_pad_values {
40 6     6 0 8 my ($self, $new_values) = @_;
41 6         93 my $pad_indices = $self->_pad_indices;
42 6         36 my @curpad = $self->_current_pad;
43 6         19 foreach my $name (keys %$new_values) {
44 18         34 my $pad_value = $curpad[$pad_indices->{$name}]->object_2svref;
45 18 100       47 if ($name =~ /^\$/) {
    50          
    0          
46 12         12 ${$pad_value} = ${$new_values->{$name}};
  12         16  
  12         19  
47             } elsif ($name =~ /^\@/) {
48 6         7 @{$pad_value} = @{$new_values->{$name}};
  6         13  
  6         10  
49             } elsif ($name =~ /^\%/) {
50 0         0 %{$pad_value} = %{$new_values->{$name}};
  0         0  
  0         0  
51             }
52             }
53 6         12 return;
54             }
55              
56             1;