| 1 | package Variable::Lazy; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Variable::Lazy::Guts; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Devel::Declare; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use B::Hooks::EndOfScope; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | our @CARP_NOT = qw/Devel::Declare/; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | my $package = caller; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | Devel::Declare->setup_for($package, { lazy => { const => \&_parser } }); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||
| 21 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | *{ $package . '::lazy' } = \&Variable::Lazy::Guts::lazy; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 2 | return; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | sub _parser { | ||||||||||||||||||||||||||
|
Subroutine
_parser: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||
| 28 | 7 | my ($declarator, $offset) = @_; | |||||||||||||||||||||||||||
| 29 | 7 | my $linestr = Devel::Declare::get_linestr; | |||||||||||||||||||||||||||
| 30 | 7 | $offset += Devel::Declare::toke_move_past_token($offset); | |||||||||||||||||||||||||||
| 31 | 7 | $offset += Devel::Declare::toke_skipspace($offset); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | if (substr($linestr, $offset, 1) eq '{') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | substr $linestr, $offset, 1, q/(Variable::Lazy::_variable(), \\@_, sub { BEGIN { Variable::Lazy::_inject_scope(')') }; /; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||
| 37 | 5 | ▶ | if (my $length = Devel::Declare::toke_scan_word($offset, 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 4 | my $word = substr $linestr, $offset, $length; | |||||||||||||||||||||||||||
| 39 | 4 | ▶ | croak "Invalid word '$word' in lazy expression" unless $word eq 'my' or $word eq 'our'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word eq "my" or $word eq "our"
MC/DC0%0/2
$word eq "my" or $word eq "our"
$word eq "my"
$word eq "our"
Truth table33%1/3
A or B
A= $word eq "my"B= $word eq "our"
| |||||||||||||||||||||||||||||
| 40 | 4 | $offset += $length; | |||||||||||||||||||||||||||
| 41 | 4 | $offset += Devel::Declare::toke_skipspace($offset); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | croak 'Variable expected' if substr($linestr, $offset, 1) ne '$'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 5 | ▶ | $offset += Devel::Declare::toke_scan_ident($offset) || croak 'Variable name expected'; | ||||||||||||||||||||||||||
|
Condition50%1/2
Devel::Declare::toke_scan_ident($offset) || croak('Variable name expected')
MC/DC0%0/1
Devel::Declare::toke_scan_ident($offset) || croak('Variable name expected')
Devel::Declare::toke_scan_ident($offset)
Truth table50%1/2
A
A= Devel::Declare::toke_scan_ident($offset)
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5 | $offset += Devel::Declare::toke_skipspace($offset); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | ▶ | croak 'Assignment expected' if substr($linestr, $offset, 1) ne '='; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 5 | substr $linestr, $offset++, 1, ','; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | $offset += Devel::Declare::toke_skipspace($offset); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | ▶ | croak 'Opening bracket expected' if substr($linestr, $offset, 1) ne '{'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 5 | substr $linestr, $offset, 1, q/\\@_, sub { /; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 7 | Devel::Declare::set_linestr($linestr); | |||||||||||||||||||||||||||
| 58 | 7 | return; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub _variable { | ||||||||||||||||||||||||||
|
Subroutine
_variable: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 2 | return my $foo; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub _inject_scope { | ||||||||||||||||||||||||||
|
Subroutine
_inject_scope: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 2 | my $terminator = shift; | |||||||||||||||||||||||||||
| 67 | 2 | ▶ | on_scope_end { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 2 | my $linestr = Devel::Declare::get_linestr; | |||||||||||||||||||||||||||
| 69 | 2 | my $offset = Devel::Declare::get_linestr_offset; | |||||||||||||||||||||||||||
| 70 | 2 | substr $linestr, $offset, 0, $terminator; | |||||||||||||||||||||||||||
| 71 | 2 | Devel::Declare::set_linestr($linestr); | |||||||||||||||||||||||||||
| 72 | 2 | }; | |||||||||||||||||||||||||||
| 73 | 2 | return; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 3 | 1; # End of Variable::Lazy | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||