File Coverage

blib/lib/XML/XPathScript/Template/Tag.pm
Criterion Covered Total %
statement 31 34 91.1
branch 4 6 66.6
condition n/a
subroutine 11 12 91.6
pod 3 3 100.0
total 49 55 89.0


line stmt bran cond sub pod time code
1             package XML::XPathScript::Template::Tag;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: XPathScript Template Element
4             $XML::XPathScript::Template::Tag::VERSION = '2.00';
5 27     27   170 use strict;
  27         54  
  27         695  
6 27     27   133 use warnings;
  27         51  
  27         566  
7              
8 27     27   140 use Carp;
  27         48  
  27         1249  
9 27     27   162 use Scalar::Util qw/ reftype /;
  27         44  
  27         1379  
10              
11 27         221 use overload '&{}' => \&_overload_func,
12 27     27   8845 q{""} => \&_overload_quote;
  27         18633  
13              
14             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             sub new {
27 2997     2997 1 6467 return bless {}, shift;
28             }
29              
30             sub get {
31 1     1 1 6 my $self = shift;
32 0         0 return wantarray ? map { $self->{$_} } @_
33 1 50       7 : $self->{$_[0]}
34             ;
35             }
36              
37             sub set {
38 49     49 1 137 my( $self, $attribute_ref ) = @_;
39              
40 49         60 for my $key ( keys %{$attribute_ref} ) {
  49         139  
41             croak "attribute $key not allowed"
42 82 50       131 if ! grep { $key eq $_ } @ALLOWED_ATTRIBUTES;
  1148         1586  
43              
44 82         160 $self->{$key} = $attribute_ref->{$key};
45              
46             # renaming implies showing the tag
47 82 100       172 $self->{showtag} = 1 if $key eq 'rename';
48             }
49              
50 49         110 return;
51             }
52              
53             sub _overload_func {
54 1     1   6 my $self = shift;
55 1     1   4 return sub { $self->set( @_ ) }
56 1         5 }
57              
58             sub _overload_quote {
59 209     209   475 my $self = shift;
60 209         514 return $self;
61 0     0     return sub { print $self };
  0            
62             }
63              
64             'end of XML::XPathScript::Template::Tag';
65              
66             __END__