File Coverage

blib/lib/RDF/RDFa/Generator/HTML/Hidden.pm
Criterion Covered Total %
statement 44 50 88.0
branch 8 14 57.1
condition 4 12 33.3
subroutine 8 8 100.0
pod 1 2 50.0
total 65 86 75.5


line stmt bran cond sub pod time code
1             package RDF::RDFa::Generator::HTML::Hidden;
2              
3 4     4   96 use 5.008;
  4         27  
4 4     4   24 use base qw'RDF::RDFa::Generator::HTML::Head';
  4         10  
  4         541  
5 4     4   29 use strict;
  4         47  
  4         127  
6 4     4   49 use XML::LibXML qw':all';
  4         9  
  4         33  
7              
8 4     4   757 use warnings;
  4         9  
  4         2351  
9              
10              
11             our $VERSION = '0.200';
12              
13             sub injection_site
14             {
15 5     5 0 31 return '//xhtml:body';
16             }
17              
18             sub nodes
19             {
20 5     5 1 26 my ($proto, $model) = @_;
21 5 50       28 my $self = (ref $proto) ? $proto : $proto->new;
22            
23 5         38 my $stream = $self->_get_stream($model);
24 5         5208 my @nodes;
25            
26 5         48 my $rootnode = XML::LibXML::Element->new('i');
27 5         29 $rootnode->setNamespace('http://www.w3.org/1999/xhtml', undef, 1);
28 5         137 $rootnode->setAttribute('style','display:none');
29            
30 5         65 my $subjects = {};
31 5         30 while (my $st = $stream->next)
32             {
33 9 100       1113 my $s = $st->subject->is_resource ?
34             $st->subject->abs :
35             ('_:'.$st->subject->value);
36 9         839 push @{ $subjects->{$s} }, $st;
  9         49  
37             }
38            
39 5         310 foreach my $s (keys %$subjects)
40             {
41 6         84 my $node = $rootnode->addNewChild('http://www.w3.org/1999/xhtml', 'i');
42            
43 6         33 $self->_process_subject($subjects->{$s}->[0], $node);
44            
45 6         29 foreach my $st (@{ $subjects->{$s} })
  6         33  
46             {
47 9         114 my $node2 = $node->addNewChild('http://www.w3.org/1999/xhtml', 'i');
48 9         56 $self->_process_predicate($st, $node2)
49             ->_process_object($st, $node2);
50             }
51             }
52            
53 5 50 33     185 if (defined($self->{'version'}) && $self->{'version'} == 1.1
      33        
54             and $self->{'prefix_attr'}) {
55 0 0       0 if (defined($self->{namespacemap}->rdfa)) {
56 0         0 $rootnode->setAttribute('prefix', $self->{namespacemap}->rdfa->as_string);
57             }
58             } else {
59 5         28 while (my ($prefix, $nsURI) = $self->{namespacemap}->each_map) {
60 89         9949 $rootnode->setNamespace($nsURI->as_string, $prefix, 0);
61             }
62             }
63            
64 5         561 push @nodes, $rootnode;
65            
66 5 50       51 return @nodes if wantarray;
67            
68 0         0 my $nodelist = XML::LibXML::NodeList->new;
69 0         0 $nodelist->push(@nodes);
70 0         0 return $nodelist;
71             }
72              
73             sub _process_subject
74             {
75 17     17   68 my ($self, $st, $node) = @_;
76            
77 17 50 33     154 if (defined $self->{'base'}
    100 33        
78             and $st->subject->is_resource
79             and $st->subject->abs eq $self->{'base'})
80 0         0 { $node->setAttribute('about', ''); }
81             elsif ($st->subject->is_resource)
82 12         717 { $node->setAttribute('about', $st->subject->abs); }
83             else
84 5         206 { $node->setAttribute('about', '[_:'.$st->subject->value.']'); }
85            
86 17         1031 return $self;
87             }
88              
89             1;