File Coverage

blib/lib/XML/ExtOn/TieAttrsName.pm
Criterion Covered Total %
statement 39 39 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 51 55 92.7


line stmt bran cond sub pod time code
1             package XML::ExtOn::TieAttrsName;
2              
3             #$id$
4              
5 9     9   44 use strict;
  9         16  
  9         307  
6 9     9   43 use warnings;
  9         21  
  9         215  
7 9     9   43 use XML::ExtOn::TieAttrs;
  9         91  
  9         279  
8 9     9   44 use base 'XML::ExtOn::TieAttrs';
  9         15  
  9         4191  
9              
10             sub GetKeys {
11 3     3 0 5 my $self = shift;
12 3         4 return [ map { $_->{Name} } values %{ $self->get_by_filter } ];
  13         29  
  3         7  
13             }
14              
15             sub create_attr {
16 1     1 0 2 my $self = shift;
17 1         2 my $key = shift;
18 1         4 my %template =
19 1         2 ( %{ $self->_template() }, @{ $self->_default() }, LocalName => $key );
  1         3  
20 1         4 my ( $prefix ) = $key =~ /([^:]+):/;
21 1         2 my $local_name = $key;
22 1 50       3 $template{Name} = $prefix ? "$prefix:$local_name" : $local_name;
23 1         4 $template{NamespaceURI} = $self->{context}->get_uri($prefix);
24 1         46 return &XML::ExtOn::TieAttrs::attr_from_sax2( { 1 => \%template } );
25             }
26              
27             sub get_by_filter {
28 32     32 0 34 my $self = shift;
29 32         32 my $flocal_name = shift;
30 32         60 my $ahash = $self->_orig_hash;
31 32         37 my %res = ();
32 32         30 my ( $field_name, $value ) = @{ $self->_default() };
  32         59  
33 32         32 my $i = -1;
34 32         40 foreach my $val (@$ahash) {
35 141         109 $i++;
36 141 100       187 if ( defined $flocal_name ) {
37 128 100       240 next unless $val->{Name} eq $flocal_name;
38             }
39 41         74 $res{$i} = $val;
40             }
41 32         119 return \%res;
42             }
43             1;