| 1 | package XML::XPathScript::Template::Tag; | ||||||||||
| 2 | 35 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: XPathScript Template Element | ||||||||||
| 4 | 35 | $XML::XPathScript::Template::Tag::VERSION = '2.00'; | |||||||||
| 5 | 35 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 35 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 35 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 35 | ▶ | use Scalar::Util qw/ reftype /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 35 | ▶ | use overload '&{}' => \&_overload_func, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 35 | q{""} => \&_overload_quote; | |||||||||
| 13 | |||||||||||
| 14 | 35 | our @ALLOWED_ATTRIBUTES = qw{ | |||||||||
| 15 | pre post | ||||||||||
| 16 | intro extro | ||||||||||
| 17 | prechildren postchildren | ||||||||||
| 18 | prechild testcode | ||||||||||
| 19 | showtag | ||||||||||
| 20 | postchild | ||||||||||
| 21 | action | ||||||||||
| 22 | rename | ||||||||||
| 23 | content contents | ||||||||||
| 24 | }; | ||||||||||
| 25 | |||||||||||
| 26 | 3056 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 3056 | return bless {}, shift; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||
| 31 | 1 | my $self = shift; | |||||||||
| 32 | 0 | return wantarray ? map { $self->{$_} } @_ | |||||||||
| 33 | 1 | ▶ | : $self->{$_[0]} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | ; | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 108 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 38 | 108 | my( $self, $attribute_ref ) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 108 | for my $key ( keys %{$attribute_ref} ) { | |||||||||
| 41 | croak "attribute $key not allowed" | ||||||||||
| 42 | 163 | ▶ | if ! grep { $key eq $_ } @ALLOWED_ATTRIBUTES; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 163 | $self->{$key} = $attribute_ref->{$key}; | |||||||||
| 45 | |||||||||||
| 46 | # renaming implies showing the tag | ||||||||||
| 47 | 163 | ▶ | $self->{showtag} = 1 if $key eq 'rename'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 108 | return; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | sub _overload_func { | ||||||||
|
Subroutine
_overload_func: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 1 | my $self = shift; | |||||||||
| 55 | 1 | ▶ | return sub { $self->set( @_ ) } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 1 | } | |||||||||
| 57 | |||||||||||
| 58 | 71 | ▶ | sub _overload_quote { | ||||||||
|
Subroutine
_overload_quote: called CC=1 SCAR=1.2
| |||||||||||
| 59 | 71 | my $self = shift; | |||||||||
| 60 | 71 | return $self; | |||||||||
| 61 | 0 | ▶ | return sub { print $self }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 35 | 'end of XML::XPathScript::Template::Tag'; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||