WithLexicals/WithHintPersistence.pm

filter: Statementstmt 100% 37 / 37 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 95.9% 47 / 49 CC 3 SCAR 3.7
CC
3
Cov
98%
_capture_unroll_global
2.0
setup_code
2.0
BEGIN
1.0
CRAP 1.4
« WithLexicals.pm ↑ Summary
1 package Eval::WithLexicals::WithHintPersistence;
2 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.003005'; # 1.3.5
6 1 $VERSION = eval $VERSION;
7  
8 1 has hints => (
9 is => 'rw',
10 default => quote_sub q{ {} },
11 );
12  
13 1 has _first_eval => (
14 is => 'rw',
15 default => quote_sub q{ 1 },
16 );
17  
18 around eval => sub {
19 6 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
20 6 my($self) = @_;
21  
22 6 local *Eval::WithLexicals::Cage::capture_hints;
23 6 local $Eval::WithLexicals::Cage::hints = { %{$self->hints} };
24  
25 6 my @ret = $orig->(@_);
26  
27 5 $self->hints({ Eval::WithLexicals::Cage::capture_hints() });
28  
29 5 @ret;
30 1 };
31  
32 # XXX: Sub::Quote::capture_unroll without 'my'
33 1 ▶use B();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 sub _capture_unroll_global {
35 5 ▶ my ($from, $captures, $indent) = @_;
Subroutine _capture_unroll_global: called CC=2 SCAR=7.0
36 join(
37 '',
38 map {
39 5 ▶ /^([\@\%\$])/
Branch: 1 branch
BranchTrueFalseTotal
/^([\@\%\$])/ or die "capture key should start with \@, % or \$: $_" 0 15 15
40 or die "capture key should start with \@, \% or \$: $_";
41 15 (' ' x $indent).qq{${_} = ${1}{${from}->{${\B::perlstring $_}}};\n};
42 } keys %$captures
43 );
44 }
45  
46 sub setup_code {
47 6 ▶ my($self) = @_;
Subroutine setup_code: called CC=2 SCAR=6.9
Pod undocumented
48 # Only run the prelude on the first eval, hints will be set after
49 # that.
50 6 ▶ if($self->_first_eval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_first_eval) { } 1 5 6
51 1 $self->_first_eval(0);
52 1 return $self->prelude;
53 } else {
54 # Seems we can't use the technique of passing via @_ for code in a BEGIN
55 # block
56 5 return q[ BEGIN { ],
57 _capture_unroll_global('$Eval::WithLexicals::Cage::hints', $self->hints, 2),
58 q[ } ],
59 }
60 };
61  
62 around capture_code => sub {
63 6 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
64 6 my($self) = @_;
65  
66 6 ( q{ sub Eval::WithLexicals::Cage::capture_hints {
67 my ($hints, %hints, $warn_bits);
68 BEGIN {
69 no warnings 'closure';
70 $hints = $^H;
71 %hints = %^H;
72 $warn_bits = ${^WARNING_BITS};
73 }
74 return (
75 q{$^H} => \$hints,
76 q{%^H} => \%hints,
77 q{${^WARNING_BITS}} => \$warn_bits,
78 );
79 } },
80 $orig->(@_) )
81 1 };
82  
83 1 1;
84 __END__
« WithLexicals.pm ↑ Summary