Role/ProcessDOAP.pm

filter: Statementstmt 26.4% 27 / 102 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 3 totaltotal 16.1% 32 / 198 CC 41 SCAR 57.9
CC
41
Cov
16%
cpanmeta_resources
600.0
__ANON__
132.0
cpanmeta_keywords
30.0
CRAP 328.3
↑ Summary Role/ProcessDOAPDeps.pm »
1 package Dist::Inkt::Role::ProcessDOAP;
2  
3 1 our $AUTHORITY = 'cpan:TOBYINK';
4 1 our $VERSION = '0.110';
5  
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::Util 'uniq';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Dist::Inkt::Role::RDFModel';
12  
13 1 ▶use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 my $CPAN = 'RDF::Trine::Namespace'->new('http://purl.org/NET/cpan-uri/terms#');
15 1 my $DC = 'RDF::Trine::Namespace'->new('http://purl.org/dc/terms/');
16 1 my $DOAP = 'RDF::Trine::Namespace'->new('http://usefulinc.com/ns/doap#');
17 1 my $DEPS = 'RDF::Trine::Namespace'->new('http://ontologi.es/doap-deps#');
18 1 my $FOAF = 'RDF::Trine::Namespace'->new('http://xmlns.com/foaf/0.1/');
19 1 my $NFO = 'RDF::Trine::Namespace'->new('http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#');
20 1 my $SKOS = 'RDF::Trine::Namespace'->new('http://www.w3.org/2004/02/skos/core#');
21  
22 after PopulateMetadata => sub
23 0 ▶{
Subroutine __ANON__: not called CC=11 SCAR=48.8
24 0 my $self = shift;
25
26 0 $self->log('Processing the DOAP vocabulary');
27
28 0 my $meta = $self->metadata;
29
30 0 ▶ delete $meta->{abstract} if $meta->{abstract} eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"abstract"} eq "unknown" 0 0 0
31 $meta->{abstract} ||= $_
32 0 ▶ for grep defined, $self->doap_project->shortdesc;
Condition0%0/3
$meta->{"abstract"} ||= $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->{"abstract"} ||= $_
$meta->{"abstract"} $_
Truth table0%0/3
A ||= B
A= $meta->{"abstract"}B= $_
ABresult
1X1
011
000
33
34 $meta->{description} ||= $_
35 0 ▶ for grep defined, $self->doap_project->description;
Condition0%0/3
$meta->{"description"} ||= $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->{"description"} ||= $_
$meta->{"description"} $_
Truth table0%0/3
A ||= B
A= $meta->{"description"}B= $_
ABresult
1X1
011
000
36
37 0 push @{ $meta->{license} }, $self->cpanmeta_license_code;
38
39 0 my $r = $self->cpanmeta_resources;
40 0 ▶ $meta->{resources}{$_} ||= $r->{$_} for keys %$r;
Condition0%0/3
$meta->{"resources"}{$_} ||= $r->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->{"resources"}{$_} ||= $r->{$_}
$meta->{"resources"}{$_} $r->{$_}
Truth table0%0/3
A ||= B
A= $meta->{"resources"}{$_}B= $r->{$_}
ABresult
1X1
011
000
41
42 0 push @{ $meta->{keywords} }, $self->cpanmeta_keywords;
43
44 0 for my $role ($self->model->objects(RDF::Trine::iri($self->project_uri), $CPAN->x_help_wanted))
45 {
46 0 ▶ next unless $role->uri =~ /(\w+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $role->uri =~ /(\w+)\z/ 0 0 0
47 0 ▶ push @{ $meta->{x_help_wanted} ||= [] }, $1;
Condition0%0/2
$meta->{"x_help_wanted"} ||= []
l!l
00
MC/DC0%0/1
$meta->{"x_help_wanted"} ||= []
$meta->{"x_help_wanted"}
Truth table0%0/2
A
A= $meta->{"x_help_wanted"}
Aresult
11
00
48 }
49 1 };
50  
51 sub cpanmeta_license_code
52 0 ▶{
Subroutine cpanmeta_license_code: not called CC=4 SCAR=30.0
Pod undocumented
53 0 my $self = shift;
54  
55 0 my @r;
56 0 for (@{ $self->doap_project->license })
57 {
58 my $license_code = {
59 'http://www.gnu.org/licenses/agpl-3.0.txt' => 'agpl_3',
60 'http://www.apache.org/licenses/LICENSE-1.1' => 'apache_1_1',
61 'http://www.apache.org/licenses/LICENSE-2.0' => 'apache_2_0',
62 'http://www.apache.org/licenses/LICENSE-2.0.txt' => 'apache_2_0',
63 'http://www.perlfoundation.org/artistic_license_1_0' => 'artistic_1',
64 'http://opensource.org/licenses/artistic-license.php' => 'artistic_1',
65 'http://www.perlfoundation.org/artistic_license_2_0' => 'artistic_2',
66 'http://opensource.org/licenses/artistic-license-2.0.php' => 'artistic_2',
67 'http://www.opensource.org/licenses/bsd-license.php' => 'bsd',
68 'http://creativecommons.org/publicdomain/zero/1.0/' => 'unrestricted',
69 'http://www.freebsd.org/copyright/freebsd-license.html' => 'freebsd',
70 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html' => 'gfdl_1_2',
71 'http://www.gnu.org/copyleft/fdl.html' => 'gfdl_1_3',
72 'http://www.opensource.org/licenses/gpl-license.php' => 'gpl_1',
73 'http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt' => 'gpl_1',
74 'http://www.opensource.org/licenses/gpl-2.0.php' => 'gpl_2',
75 'http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt' => 'gpl_2',
76 'http://www.opensource.org/licenses/gpl-3.0.html' => 'gpl_3',
77 'http://www.gnu.org/licenses/gpl-3.0.txt' => 'gpl_3',
78 'http://www.opensource.org/licenses/lgpl-license.php' => 'open_source',
79 'http://www.opensource.org/licenses/lgpl-2.1.php' => 'lgpl_2_1',
80 'http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' => 'lgpl_2_1',
81 'http://www.opensource.org/licenses/lgpl-3.0.html' => 'lgpl_3_0',
82 'http://www.gnu.org/licenses/lgpl-3.0.txt' => 'lgpl_3_0',
83 'http://www.opensource.org/licenses/mit-license.php' => 'mit',
84 'http://www.mozilla.org/MPL/MPL-1.0.txt' => 'mozilla_1_0',
85 'http://www.mozilla.org/MPL/MPL-1.1.txt' => 'mozilla_1_1',
86 'http://opensource.org/licenses/mozilla1.1.php' => 'mozilla_1_1',
87 'http://www.openssl.org/source/license.html' => 'openssl',
88 'http://dev.perl.org/licenses/' => 'perl_5',
89 'http://www.opensource.org/licenses/postgresql' => 'open_source',
90 'http://trolltech.com/products/qt/licenses/licensing/qpl' => 'qpl_1_0',
91 'http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html' => 'ssleay',
92 'http://www.openoffice.org/licenses/sissl_license.html' => 'sun',
93 'http://www.zlib.net/zlib_license.html' => 'zlib',
94 0 }->{ $_->uri };
95  
96 0 ▶ push @r, $license_code if $license_code;
Branch: 1 branch
BranchTrueFalseTotal
if $license_code 0 0 0
97 }
98
99 0 ▶ @r ? uniq(@r) : ('unknown');
Branch: 1 branch
BranchTrueFalseTotal
@r ? : 0 0 0
100 }
101  
102 sub cpanmeta_resources
103 0 ▶{
Subroutine cpanmeta_resources: not called CC=24 SCAR=64.0
Pod undocumented
104 0 my $self = shift;
105  
106 0 my %resources;
107
108 0 $resources{license} = [ map $_->uri, @{ $self->doap_project->license } ];
109 0 ▶ $resources{homepage} ||= $_->uri for @{ $self->doap_project->homepage };
Condition0%0/3
$resources{"homepage"} ||= $_->uri
l!l&&r!l&&!r
000
MC/DC0%0/2
$resources{"homepage"} ||= $_->uri
$resources{"homepage"} $_->uri
Truth table0%0/3
A ||= B
A= $resources{"homepage"}B= $_->uri
ABresult
1X1
011
000
110
111 0 my (@bug) = map $_->uri, $self->doap_project->bug_database;
112 0 for (@bug) {
113 0 ▶ if (/^mailto:(.+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^mailto:(.+)/i) { } 0 0 0
114 0 ▶ $resources{bugtracker}{mailto} ||= $1;
Condition0%0/3
$resources{"bugtracker"}{"mailto"} ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$resources{"bugtracker"}{"mailto"} ||= $1
$resources{"bugtracker"}{"mailto"} $1
Truth table0%0/3
A ||= B
A= $resources{"bugtracker"}{"mailto"}B= $1
ABresult
1X1
011
000
115 }
116 else {
117 0 ▶ $resources{bugtracker}{web} ||= $_;
Condition0%0/3
$resources{"bugtracker"}{"web"} ||= $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$resources{"bugtracker"}{"web"} ||= $_
$resources{"bugtracker"}{"web"} $_
Truth table0%0/3
A ||= B
A= $resources{"bugtracker"}{"web"}B= $_
ABresult
1X1
011
000
118 }
119 }
120
121 0 ▶ REPO: for my $repo (@{$self->doap_project->repository || []})
Condition0%0/2
$self->doap_project->repository || []
l!l
00
MC/DC0%0/1
$self->doap_project->repository || []
$self->doap_project->repository
Truth table0%0/2
A
A= $self->doap_project->repository
Aresult
11
00
122 {
123 0 ▶ if ($repo->location || $repo->browse)
Branch: 1 branch
BranchTrueFalseTotal
if ($repo->location or $repo->browse) 0 0 0
Condition0%0/3
$repo->location or $repo->browse
l!l&&r!l&&!r
000
MC/DC0%0/2
$repo->location or $repo->browse
$repo->location $repo->browse
Truth table0%0/3
A or B
A= $repo->locationB= $repo->browse
ABresult
1X1
011
000
124 {
125 0 my $r = {};
126 0 ▶ $r->{url} = $repo->location->uri if $repo->location;
Branch: 1 branch
BranchTrueFalseTotal
if $repo->location 0 0 0
127 0 ▶ $r->{web} = $repo->browse->uri if $repo->browse;
Branch: 1 branch
BranchTrueFalseTotal
if $repo->browse 0 0 0
128 0 ▶ for my $type (@{ $repo->rdf_type || [] })
Condition0%0/2
$repo->rdf_type || []
l!l
00
MC/DC0%0/1
$repo->rdf_type || []
$repo->rdf_type
Truth table0%0/2
A
A= $repo->rdf_type
Aresult
11
00
129 {
130 0 ▶ $r->{type} ||= lc($1) if $type->uri =~ m{[/#](\w+)Repository$};
Branch: 1 branch
BranchTrueFalseTotal
if $type->uri =~ m[[/#](\w+)Repository$] 0 0 0
Condition0%0/3
$r->{"type"} ||= lc $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$r->{"type"} ||= lc $1
$r->{"type"} lc $1
Truth table0%0/3
A ||= B
A= $r->{"type"}B= lc $1
ABresult
1X1
011
000
131 }
132 0 ▶ if ($r->{web} =~ m{^https?://github.com/([^/]+)/([^/]+)$})
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"web"} =~ m[^https?://github.com/([^/]+)/([^/]+)$]) 0 0 0
133 {
134 0 ▶ $r->{url} ||= sprintf('git://github.com/%s/%s.git', $1, $2);
Condition0%0/2
$r->{"url"} ||= sprintf('git://github.com/%s/%s.git', $1, $2)
l!l
00
MC/DC0%0/1
$r->{"url"} ||= sprintf('git://github.com/%s/%s.git', $1, $2)
$r->{"url"}
Truth table0%0/2
A
A= $r->{"url"}
Aresult
11
00
135 0 ▶ $r->{type} ||= 'git';
Condition0%0/2
$r->{"type"} ||= "git"
l!l
00
MC/DC0%0/1
$r->{"type"} ||= "git"
$r->{"type"}
Truth table0%0/2
A
A= $r->{"type"}
Aresult
11
00
136 }
137 0 $resources{repository} = $r;
138 0 last REPO;
139 }
140 }
141
142 ($resources{x_mailinglist}) =
143 0 map { $_->uri }
144 grep defined,
145 $self->doap_project->mailing_list;
146
147 ($resources{x_wiki}) =
148 0 map { $_->uri }
149 grep defined,
150 $self->doap_project->wiki;
151
152 ($resources{x_identifier}) =
153 0 map { $_->uri }
154 grep defined,
155 $self->doap_project->rdf_about;
156
157 ($resources{x_IRC}) =
158 0 map { $_->uri }
159 grep defined,
160 $self->model->objects(RDF::Trine::iri($self->project_uri), $CPAN->x_IRC);
161  
162 0 ▶ if (defined($self->doap_project->support_forum)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->doap_project->support_forum) 0 0 0
163 0 foreach my $forum (@{ $self->doap_project->support_forum }) {
164 0 my $forumuri = URI->new($forum->uri);
165 0 ▶ if ($forumuri->scheme =~ m/^ircs?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forumuri->scheme =~ /^ircs?$/) 0 0 0
166 0 $resources{x_IRC} = $forumuri->as_string;
167 0 last;
168 }
169 }
170 }
171  
172 0 delete $resources{$_} for grep !defined $resources{$_}, keys %resources;
173
174 0 return \%resources;
175 }
176  
177 sub cpanmeta_keywords
178 0 ▶{
Subroutine cpanmeta_keywords: not called CC=5 SCAR=34.0
Pod undocumented
179 0 my $self = shift;
180 0 my $model = $self->model;
181
182 0 my %keywords;
183 0 ▶ CATEGORY: for my $cat (@{ $self->doap_project->category || [] })
Condition0%0/2
$self->doap_project->category || []
l!l
00
MC/DC0%0/1
$self->doap_project->category || []
$self->doap_project->category
Truth table0%0/2
A
A= $self->doap_project->category
Aresult
11
00
184 {
185 0 LABEL: for my $label ($model->objects_for_predicate_list($cat, $SKOS->prefLabel, $RDFS->label, $DOAP->name, $FOAF->name))
186 {
187 0 ▶ next LABEL unless $label->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $label->is_literal 0 0 0
188 0 $keywords{ uc $label->literal_value } = $label->literal_value;
189 0 next CATEGORY;
190 }
191 }
192
193 0 sort values %keywords;
194 }
195  
196 1 1;
↑ Summary Role/ProcessDOAPDeps.pm »