| 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
| |||||||||||
| 58 | { | ||||||||||
| 59 | 302 | my $context = $self->[$i]; | |||||||||
| 60 | 302 | ▶ | if (blessed $context) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | { | ||||||||||
| 62 | 0 | ▶ | if ($context->can($element)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | my @ret = $context->$element(); # array context | |||||||||
| 64 | 0 | ▶ | return @ret if wantarray(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 69 | |||||||||||
| 70 | 302 | ▶ | return $context->{$element} if exists $context->{$element}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||