| 1 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package Template::Pure::DataContext; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Template::Pure::UndefObject; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | use overload | ||||||||||||||||||||
| 11 | 0 | ▶ | q{""} => sub { shift->value }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 12 | 1 | ▶ | 'fallback' => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||
| 15 | 0 | ▶ | my ($proto, $data_proto, $root) = @_; | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 16 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 17 | 0 | ▶ | return bless +{ | ||||||||||||||||||
|
Condition0%0/3
$root || $data_proto
MC/DC0%0/2
$root || $data_proto
$root
$data_proto
Truth table0%0/3
A || B
A= $rootB= $data_proto
| |||||||||||||||||||||
| 18 | value => $data_proto, | ||||||||||||||||||||
| 19 | root => ($root||$data_proto), | ||||||||||||||||||||
| 20 | }, $class; | ||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub value { shift->{value} } | ||||||||||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | sub at { | ||||||||||||||||||||
| 26 | my ($self, %at) = @_; | ||||||||||||||||||||
| 27 | my $current = $at{absolute} ? $self->{root} : $self->{value}; | ||||||||||||||||||||
| 28 | foreach my $at(@{$at{path}}) { | ||||||||||||||||||||
| 29 | my $key = $at->{key} || die "missing key"; | ||||||||||||||||||||
| 30 | if(blessed $current) { | ||||||||||||||||||||
| 31 | if($current->can($key)) { | ||||||||||||||||||||
| 32 | $current = $current->$key; | ||||||||||||||||||||
| 33 | } elsif($at->{optional}) { | ||||||||||||||||||||
| 34 | $current = undef; | ||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||
| 36 | 1 | ▶ | use Devel::Dwarn; Dwarn $current; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||||||||||||||||||||
| 37 | die "Missing path '$key'"; | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | } elsif(ref $current eq 'HASH') { | ||||||||||||||||||||
| 40 | if(exists $current->{$key}) { | ||||||||||||||||||||
| 41 | $current = $current->{$key}; | ||||||||||||||||||||
| 42 | } elsif($at->{optional}) { | ||||||||||||||||||||
| 43 | $current = undef; | ||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||
| 45 | warn Dumper $at; | ||||||||||||||||||||
| 46 | die "Missing path '$key'"; | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||
| 49 | die "Can't find path '$key' in ". Dumper $current; | ||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | if($at->{maybe}) { | ||||||||||||||||||||
| 52 | $current = Template::Pure::UndefObject->maybe($current); | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | return $self->new($current, $self->{root}); | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1; | ||||||||||||||||||||
| 59 | |||||||||||||||||||||