blib/lib/RDF/DOAP/Lite.pm

filter: Statementstmt 16.9% 29 / 171 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 38.8% 7 / 18 Podpod 45.4% 5 / 11 totaltotal 14.1% 41 / 289 CC 64 SCAR 59.1
CC
64
Cov
12%
doap_xml
650.0
doap_ttl
552.0
xml_person
50.1
CRAP 367.0
↑ Summary
1 1 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package RDF::DOAP::Lite;
7  
8 1 our $AUTHORITY = 'cpan:TOBYINK';
9 1 our $VERSION = '0.002';
10  
11 1 ▶use CPAN::Meta 2.110320 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util 1.24 qw( openhandle );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # ============= helper functions =============
15  
16 sub parse_person
17 0 ▶{
Subroutine parse_person: not called CC=3 SCAR=24.8
Pod undocumented
18 0 ▶ $_[0] =~ m{ \A \s*
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \A \s* (\S.+) (?: \s+ \((\w+)\) ) (?: \s+ <(?:mailto\:)?(.+)> ) \s* \z /xi and return $1, $2, $3 0 0 0
19 (\S.+)
20 (?:
21 \s+ \((\w+)\)
22 )
23 (?:
24 \s+ <(?:mailto\:)?(.+)>
25 )
26 \s* \z }ix and return ($1, $2, $3);
27
28 0 ▶ $_[0] =~ m{ \A \s*
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \A \s* (\S.+) (?: \s+ <(?:mailto\:)?(.+)> ) \s* \z /xi and return $1, undef, $2 0 0 0
29 (\S.+)
30 (?:
31 \s+ <(?:mailto\:)?(.+)>
32 )
33 \s* \z }ix and return ($1, undef, $2);
34
35 0 return $_[0];
36 }
37  
38 {
39 1 my %TURTLE = ( "\t" => "\\t", "\n" => "\\n", "\r" => "\\r", "\"" => "\\\"", "\\" => "\\\\" );
40 sub turtle_literal
41 0 ▶ {
Subroutine turtle_literal: not called CC=2 SCAR=11.6
Pod undocumented
42 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 0 local $_ = $_[0];
44 0 ▶ return q[""] if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 0 0
45 0 s{([\t\n\r\"\\])}{$TURTLE{$1}}sg;
46 0 qq("$_");
47 }
48 }
49  
50 sub turtle_person
51 1 ▶{
Subroutine turtle_person: not called CC=7 SCAR=39.1
Pod undocumented
52 0 my ($name, $nick, $mbox) = parse_person @_;
53  
54 0 ▶ unless (defined $nick or defined $mbox)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick or defined $mbox) 0 0 0
Condition0%0/3
defined $nick or defined $mbox
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $nick or defined $mbox
defined $nick defined $mbox
Truth table0%0/3
A or B
A= defined $nickB= defined $mbox
ABresult
1X1
011
000
55 {
56 0 ▶ return '[ a foaf:Person ]' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
57 0 return sprintf('[ a foaf:Person; rdfs:label %s ]', turtle_literal $name);
58 }
59  
60 0 my $person = '[ a foaf:Person';
61 0 ▶ $person .= sprintf('; foaf:name %s', turtle_literal $name) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
62 0 ▶ $person .= sprintf('; foaf:nick %s', turtle_literal $nick) if defined $nick;
Branch: 1 branch
BranchTrueFalseTotal
if defined $nick 0 0 0
63 0 ▶ $person .= sprintf('; foaf:mbox <mailto:%s>', $mbox) if defined $mbox;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mbox 0 0 0
64 0 $person .= ' ]';
65 }
66  
67 {
68 1 my %XML = ('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;');
69 sub xml_literal
70 0 ▶ {
Subroutine xml_literal: not called CC=1 SCAR=6.9
Pod undocumented
71 0 local $_ = shift;
72 0 s{([&"<>])}{$XML{$1}}sg;
73 0 return $_;
74 }
75 }
76  
77 sub xml_person
78 1 ▶{
Subroutine xml_person: not called CC=7 SCAR=39.1
Pod undocumented
79 0 my ($name, $nick, $mbox) = parse_person @_;
80
81 0 ▶ unless (defined $nick or defined $mbox)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick or defined $mbox) 0 0 0
Condition0%0/3
defined $nick or defined $mbox
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $nick or defined $mbox
defined $nick defined $mbox
Truth table0%0/3
A or B
A= defined $nickB= defined $mbox
ABresult
1X1
011
000
82 {
83 0 ▶ return '<foaf:Person />' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
84 0 return sprintf('<foaf:Person rdfs:label="%s" />', xml_literal $name);
85 }
86
87 0 my $person = "<foaf:Person>\n";
88 0 ▶ $person .= sprintf(" <foaf:name>%s</foaf:name>\n", xml_literal $name) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
89 0 ▶ $person .= sprintf(" <foaf:nick>%s</foaf:nick>\n", xml_literal $nick) if defined $nick;
Branch: 1 branch
BranchTrueFalseTotal
if defined $nick 0 0 0
90 0 ▶ $person .= sprintf(" <foaf:mbox rdf:resource=\"mailto:%s\" />\n", xml_literal $mbox) if defined $mbox;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mbox 0 0 0
91 0 $person .= " </foaf:Person>";
92
93 0 return $person;
94 }
95  
96 sub rdf_datetype
97 0 ▶{
Subroutine rdf_datetype: not called CC=2 SCAR=17.9
Pod undocumented
98 0 ▶ ($_[0] =~ m{ \A [0-9]{4} - [0-9]{2} - [0-9]{2} \z }x) ? 'date' : 'dateTime';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \A [0-9]{4} - [0-9]{2} - [0-9]{2} \z /x ? : 0 0 0
99 }
100  
101 # ============= class definition =============
102  
103 0 ▶sub new { my $c = shift; bless { @_==1 ? %{$_[0]} : @_ }, $c }
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
104 0 ▶sub meta { $_[0]{meta} }
Subroutine meta: not called CC=1 SCAR=6.9
Pod documented
105 0 ▶sub changes { $_[0]{changes} }
Subroutine changes: not called CC=1 SCAR=6.9
Pod documented
106  
107 1 my %LICENSE = qw(
108 agpl_3 http://www.gnu.org/licenses/agpl-3.0.txt
109 apache_1_1 http://www.apache.org/licenses/LICENSE-1.1
110 apache_2_0 http://www.apache.org/licenses/LICENSE-2.0.txt
111 artistic_1 http://www.perlfoundation.org/artistic_license_1_0
112 artistic_2 http://www.perlfoundation.org/artistic_license_2_0
113 bsd http://www.opensource.org/licenses/bsd-license.php
114 freebsd http://www.freebsd.org/copyright/freebsd-license.html
115 gfdl_1_2 http://www.gnu.org/licenses/fdl-1.2.html
116 gfdl_1_3 http://www.gnu.org/licenses/fdl-1.3.html
117 gpl_1 http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt
118 gpl_2 http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
119 gpl_3 http://www.gnu.org/licenses/gpl-3.0.txt
120 lgpl_2_1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
121 lgpl_3_0 http://www.gnu.org/licenses/lgpl-3.0.txt
122 mit http://www.opensource.org/licenses/mit-license.php
123 mozilla_1_0 http://www.mozilla.org/MPL/MPL-1.0.txt
124 mozilla_1_1 http://www.mozilla.org/MPL/MPL-1.1.txt
125 openssl http://www.openssl.org/source/license.html
126 perl http://dev.perl.org/licenses/
127 perl_5 http://dev.perl.org/licenses/
128 qpl_1_0 http://trolltech.com/products/qt/licenses/licensing/qpl
129 ssleay http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html
130 sun http://www.openoffice.org/licenses/sissl_license.html
131 zlib http://www.zlib.net/zlib_license.html
132 );
133  
134 1 my %REPO = qw(
135 cvs CVS
136 git Git
137 hg Hg
138 svn SVN
139 );
140  
141 sub doap_ttl
142 0 ▶{
Subroutine doap_ttl: not called CC=23 SCAR=63.1
Pod documented
143 0 my $self = shift;
144 my $fh = openhandle($_[0])
145 ? $_[0]
146 0 ▶ : do { open my $fh, '>', $_[0] or die("Could not open $_[0]: $!"); $fh };
Branch: 2 branches
BranchTrueFalseTotal
&openhandle($_[0]) ? : 0 0 0
open my $fh, ">", $_[0] or die "Could not open $_[0]: $!" 0 0 0
147
148 0 print {$fh} <<' HEADER', "\n";
149 @prefix : <http://usefulinc.com/ns/doap#>.
150 @prefix dc: <http://purl.org/dc/terms/>.
151 @prefix foaf: <http://xmlns.com/foaf/0.1/>.
152 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
153 @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
154 HEADER
155
156 0 ▶ my $meta = $self->meta or die("no meta!");
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $self->meta or die "no meta!" 0 0 0
157 0 my $res = $meta->resources;
158 0 ▶ my $uri = $res->{X_identifier} ? "<$res->{X_identifier}>" : '[]';
Branch: 1 branch
BranchTrueFalseTotal
$res->{'X_identifier'} ? : 0 0 0
159
160 0 printf {$fh} "$uri\n";
161 0 printf {$fh} " a :Project;\n";
162 0 printf {$fh} " :name %s;\n", turtle_literal($_) for grep defined, $meta->name;
163 0 printf {$fh} " :shortdesc %s;\n", turtle_literal($_) for grep defined, $meta->abstract;
164 0 printf {$fh} " :description %s;\n", turtle_literal($_) for grep defined, $meta->description;
165 0 printf {$fh} " :category [ rdfs:label %s ];\n", turtle_literal($_) for grep defined, $meta->keywords;
166 0 printf {$fh} " :developer %s;\n", turtle_person($_) for grep defined, $meta->authors;
167 0 ▶ printf {$fh} " :helper %s;\n", turtle_person($_) for grep defined, @{ $meta->{x_contributors} || [] };
Condition0%0/2
$meta->{'x_contributors'} || []
l!l
00
MC/DC0%0/1
$meta->{'x_contributors'} || []
$meta->{'x_contributors'}
Truth table0%0/2
A
A= $meta->{'x_contributors'}
Aresult
11
00
168 0 ▶ printf {$fh} " :license <%s>;\n", $_ for map { $LICENSE{$_} || () } $meta->licenses;
Condition0%0/3
$LICENSE{$_} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$LICENSE{$_} || ()
$LICENSE{$_} ()
Truth table0%0/3
A || B
A= $LICENSE{$_}B= ()
ABresult
1X1
011
000
169 0 printf {$fh} " :homepage <%s>;\n", $_ for grep defined, $res->{homepage};
170 0 printf {$fh} " :bug-database <%s>;\n", $_ for grep defined, $res->{bugtracker}{web};
171 0 ▶ if (my $repo = $res->{repository})
Branch: 1 branch
BranchTrueFalseTotal
if (my $repo = $res->{"repository"}) 0 0 0
172 {
173 0 printf {$fh} " :repository [\n";
174 0 ▶ printf {$fh} " a :%sRepository;\n", $_ for map { $REPO{$_} || '' } $repo->{type};
Condition0%0/2
$REPO{$_} || ''
l!l
00
MC/DC0%0/1
$REPO{$_} || ''
$REPO{$_}
Truth table0%0/2
A
A= $REPO{$_}
Aresult
11
00
175 0 printf {$fh} " :browse <%s>;\n", $_ for grep defined, $repo->{web};
176 0 printf {$fh} " :location <%s>;\n", $_ for grep defined, $repo->{url};
177 0 printf {$fh} " ];\n";
178 }
179 0 for my $r (map $_->releases, grep defined, $self->changes)
180 {
181 $r->date
182 0 ? printf {$fh} " :release [ a :Version; :revision %s^^xsd:string; dc:issued %s^^xsd:%s ];\n", turtle_literal($r->version), turtle_literal($r->date), rdf_datetype($r->date)
183 0 ▶ : printf {$fh} " :release [ a :Version; :revision %s^^xsd:string ];\n", turtle_literal($r->version)
Branch: 1 branch
BranchTrueFalseTotal
$r->date ? : 0 0 0
184 }
185 0 printf {$fh} " :programming-language %s.\n", turtle_literal("Perl");
186 }
187  
188 sub doap_xml
189 0 ▶{
Subroutine doap_xml: not called CC=25 SCAR=64.8
Pod documented
190 0 my $self = shift;
191 my $fh = openhandle($_[0])
192 ? $_[0]
193 0 ▶ : do { open my $fh, '>', $_[0] or die("Could not open $_[0]: $!"); $fh };
Branch: 2 branches
BranchTrueFalseTotal
&openhandle($_[0]) ? : 0 0 0
open my $fh, ">", $_[0] or die "Could not open $_[0]: $!" 0 0 0
194
195 0 print {$fh} <<' HEADER';
196 <?xml version="1.0" encoding="UTF-8" ?>
197 <Project
198 xmlns="http://usefulinc.com/ns/doap#"
199 xmlns:dc="http://purl.org/dc/terms/"
200 xmlns:foaf="http://xmlns.com/foaf/0.1/"
201 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
202 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
203 HEADER
204
205 0 ▶ my $meta = $self->meta or die("no meta!");
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $self->meta or die "no meta!" 0 0 0
206 0 my $res = $meta->resources;
207
208 0 ▶ if ($res->{X_identifier})
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{'X_identifier'}) { } 0 0 0
209 {
210 0 printf {$fh} " rdf:about=\"%s\">\n", xml_literal($res->{X_identifier});
211 }
212 else
213 {
214 0 printf {$fh} " >\n";
215 }
216
217 0 printf {$fh} " <name>%s</name>\n", xml_literal($_) for grep defined, $meta->name;
218 0 printf {$fh} " <shortdesc>%s</shortdesc>\n", xml_literal($_) for grep defined, $meta->abstract;
219 0 printf {$fh} " <description>%s</description>\n", xml_literal($_) for grep defined, $meta->description;
220 0 printf {$fh} " <category rdfs:label=\"%s\" />\n", xml_literal($_) for grep defined, $meta->keywords;
221 0 printf {$fh} " <developer>\n %s\n </developer>\n", xml_person($_) for grep defined, $meta->authors;
222 0 ▶ printf {$fh} " <helper>\n %s\n </helper>\n", xml_person($_) for grep defined, @{ $meta->{x_contributors} || [] };
Condition0%0/2
$meta->{'x_contributors'} || []
l!l
00
MC/DC0%0/1
$meta->{'x_contributors'} || []
$meta->{'x_contributors'}
Truth table0%0/2
A
A= $meta->{'x_contributors'}
Aresult
11
00
223 0 ▶ printf {$fh} " <license rdf:resource=\"%s\" />\n", xml_literal($_) for map { $LICENSE{$_} || () } $meta->licenses;
Condition0%0/3
$LICENSE{$_} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$LICENSE{$_} || ()
$LICENSE{$_} ()
Truth table0%0/3
A || B
A= $LICENSE{$_}B= ()
ABresult
1X1
011
000
224 0 printf {$fh} " <homepage rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $res->{homepage};
225 0 printf {$fh} " <bug-database rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $res->{bugtracker}{web};
226 0 ▶ if (my $repo = $res->{repository})
Branch: 1 branch
BranchTrueFalseTotal
if (my $repo = $res->{"repository"}) 0 0 0
227 {
228 0 printf {$fh} " <repository>\n";
229 0 ▶ printf {$fh} " <%sRepository>\n", $_ for map { $REPO{$_} || '' } $repo->{type};
Condition0%0/2
$REPO{$_} || ''
l!l
00
MC/DC0%0/1
$REPO{$_} || ''
$REPO{$_}
Truth table0%0/2
A
A= $REPO{$_}
Aresult
11
00
230 0 printf {$fh} " <browse rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $repo->{web};
231 0 printf {$fh} " <location rdf:resource=\"%s\" />\n", xml_literal($_) for grep defined, $repo->{url};
232 0 ▶ printf {$fh} " </%sRepository>\n", $_ for map { $REPO{$_} || '' } $repo->{type};
Condition0%0/2
$REPO{$_} || ''
l!l
00
MC/DC0%0/1
$REPO{$_} || ''
$REPO{$_}
Truth table0%0/2
A
A= $REPO{$_}
Aresult
11
00
233 0 printf {$fh} " </repository>\n";
234 }
235 0 for my $r (map $_->releases, grep defined, $self->changes)
236 {
237 $r->date
238 0 ? printf {$fh} " <release>\n <Version>\n <revision rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</revision>\n <dc:issued rdf:datatype=\"http://www.w3.org/2001/XMLSchema#%s\">%s</dc:issued>\n </Version>\n </release>\n", xml_literal($r->version), rdf_datetype($r->date), xml_literal($r->date)
239 0 ▶ : printf {$fh} " <release>\n <Version>\n <revision rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</revision>\n </Version>\n </release>\n", xml_literal($r->version)
Branch: 1 branch
BranchTrueFalseTotal
$r->date ? : 0 0 0
240 }
241 0 printf {$fh} " <programming-language>%s</programming-language>\n", xml_literal("Perl");
242 0 printf {$fh} "</Project>\n";
243 }
244  
245 1 1;
246  
247 __END__
↑ Summary