Simple/ContextStack.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 78.8% 56 / 71 CC 7 SCAR 16.0
CC
7
Cov
82%
search
10.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.9
« Simple.pm ↑ Summary
1 package Mustache::Simple::ContextStack;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = version->declare('v1.3.8');
9  
10 4 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 our @CARP_NOT = qw(Mustache::Simple);
13  
14 # Don't forget to change the version in the pod
15  
16 #use Data::Dumper;
17 #$Data::Dumper::Useqq = 1;
18 #$Data::Dumper::Deparse = 1;
19 #
20 #use Data::Dump qw(dumpf);
21 #
22 #sub debug($)
23 #{
24 # say dumpf(shift, sub {
25 # my ($ctx, $ref) = @_;
26 # return { dump => qq(<$ref>) } if $ctx->object_isa('DateTime');
27 # }
28 # );
29 # say "-" x 50;
30 #}
31  
32 sub new
33 98 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 98 my $class = shift;
35 98 my $self = [];
36 98 bless $self, $class;
37 }
38  
39 sub push
40 222 ▶{
Subroutine push: called CC=1 SCAR=0.0
Pod undocumented
41 222 my $self = shift;
42 222 my $context = shift;
43 222 push @$self, $context;
44 }
45  
46 sub pop
47 222 ▶{
Subroutine pop: called CC=1 SCAR=0.0
Pod undocumented
48 222 my $self = shift;
49 222 my $context = pop @$self;
50 222 return $context;
51 }
52  
53 sub search
54 186 ▶{
Subroutine search: called CC=7 SCAR=23.6
Pod undocumented
55 186 my $self = shift;
56 186 my $element = shift;
57 186 ▶ for (my $i = $#$self; $i >= 0; $i--)
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 302 5 307
58 {
59 302 my $context = $self->[$i];
60 302 ▶ if (blessed $context)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($context)) 0 302 302
61 {
62 0 ▶ if ($context->can($element)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->can($element)) 0 0 0
63 0 my @ret = $context->$element(); # array context
64 0 ▶ return @ret if wantarray();
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
65 0 return $ret[0]; # first elt will be answer if non-array context
66 }
67 }
68 302 ▶ next unless reftype $context eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($context) eq "HASH" 0 302 302
69  
70 302 ▶ return $context->{$element} if exists $context->{$element};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{$element} 181 121 302
71 }
72 5 return undef;
73 }
74  
75 sub top
76 10 ▶{
Subroutine top: called CC=1 SCAR=0.0
Pod undocumented
77 10 my $self = shift;
78 10 return $self->[-1];
79 }
80  
81 4 1;
« Simple.pm ↑ Summary