File Coverage

blib/lib/RDF/Notation3/XML.pm
Criterion Covered Total %
statement 9 60 15.0
branch 0 6 0.0
condition n/a
subroutine 3 13 23.0
pod 0 10 0.0
total 12 89 13.4


line stmt bran cond sub pod time code
1 1     1   584 use strict;
  1         3  
  1         81  
2             #use warnings;
3              
4             package RDF::Notation3::XML;
5              
6             require 5.005_62;
7 1     1   6 use RDF::Notation3;
  1         2  
  1         43  
8 1     1   587 use RDF::Notation3::Template::TXML;
  1         2  
  1         798  
9              
10             ############################################################
11              
12             @RDF::Notation3::XML::ISA =
13             qw(RDF::Notation3::Template::TXML RDF::Notation3);
14              
15              
16             sub parse_file {
17 0     0 0   my ($self, $path) = @_;
18 0 0         $self->_do_error(1, '') unless @_ > 1;
19              
20 0           $self->{xml} = [];
21 0           $self->{count} = 0;
22              
23 0           $self->doStartDocument;
24 0           $self->SUPER::parse_file($path);
25 0           $self->doEndDocument;
26 0           return $self->{count};
27             }
28              
29              
30             sub parse_string {
31 0     0 0   my ($self, $str) = @_;
32 0 0         $self->_do_error(3, '') unless @_ > 1;
33              
34 0           $self->{xml} = [];
35 0           $self->{count} = 0;
36              
37 0           $self->doStartDocument;
38 0           $self->SUPER::parse_string($str);
39 0           $self->doEndDocument;
40 0           return $self->{count};
41             }
42              
43              
44             sub get_arrayref {
45 0     0 0   my $self = shift;
46 0           return $self->{xml};
47             }
48              
49              
50             sub get_array {
51 0     0 0   my $self = shift;
52 0           my $xml = $self->{xml};
53 0           return @$xml;
54             }
55              
56              
57             sub get_string {
58 0     0 0   my $self = shift;
59 0           my $xml = $self->{xml};
60 0           return join "\n", @$xml, '';
61             }
62              
63              
64             sub doStartDocument {
65 0     0 0   my $self = shift;
66 0           $self->{level} = 0;
67 0           push @{$self->{xml}},
  0            
68             "";
69              
70 0           my @attr = (['xmlns:rdf','http://www.w3.org/1999/02/22-rdf-syntax-ns#']);
71 0           $self->doStartElement('rdf:RDF', \@attr);
72             }
73              
74              
75             sub doEndDocument {
76 0     0 0   my $self = shift;
77 0           $self->doEndElement('rdf:RDF');
78             }
79              
80              
81             sub doStartElement {
82 0     0 0   my ($self, $tag, $attr) = @_;
83 0           my $element = ' ' x $self->{level}++
84             . "<$tag "
85 0           . join(' ', map {qq/$_->[0]="$_->[1]"/} @$attr)
86             . ">";
87 0           $element =~ s/ >$/>/;
88 0           push @{$self->{xml}}, $element;
  0            
89             }
90              
91              
92             sub doEndElement {
93 0     0 0   my ($self, $tag) = @_;
94 0           push @{$self->{xml}},
  0            
95             ' ' x --$self->{level}
96             . "";
97             }
98              
99              
100             sub doElement {
101 0     0 0   my ($self, $tag, $attr, $value) = @_;
102 0           my $element = ' ' x $self->{level}
103             . "<$tag "
104 0           . join(' ', map {qq/$_->[0]="$_->[1]"/} @$attr)
105             . '>';
106 0           $element =~ s/ >$/>/;
107 0 0         if ($value) {
108 0           $element .= $value;
109 0           $element .= "";
110             } else {
111 0           $element =~ s/>$/\/>/;
112             }
113 0           push @{$self->{xml}}, $element;
  0            
114             }
115              
116              
117             1;
118              
119              
120             __END__