File Coverage

blib/lib/Dist/Inkt/Role/ProcessDOAPDeps.pm
Criterion Covered Total %
statement 18 94 19.1
branch 0 24 0.0
condition 0 38 0.0
subroutine 6 9 66.6
pod 0 3 0.0
total 24 168 14.2


line stmt bran cond sub pod time code
1             package Dist::Inkt::Role::ProcessDOAPDeps;
2              
3             our $AUTHORITY = 'cpan:TOBYINK';
4             our $VERSION = '0.022';
5              
6 1     1   1201 use Moose::Role;
  1         2  
  1         7  
7 1     1   4954 use namespace::autoclean;
  1         2  
  1         7  
8              
9             with 'Dist::Inkt::Role::RDFModel';
10              
11 1     1   78 use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
  1         2  
  1         7  
12             my $CPAN = RDF::Trine::Namespace->new('http://purl.org/NET/cpan-uri/terms#');
13             my $DC = RDF::Trine::Namespace->new('http://purl.org/dc/terms/');
14             my $DOAP = RDF::Trine::Namespace->new('http://usefulinc.com/ns/doap#');
15             my $DEPS = RDF::Trine::Namespace->new('http://ontologi.es/doap-deps#');
16             my $FOAF = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/');
17             my $NFO = RDF::Trine::Namespace->new('http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#');
18             my $SKOS = RDF::Trine::Namespace->new('http://www.w3.org/2004/02/skos/core#');
19              
20             after PopulateMetadata => sub
21             {
22             my $self = shift;
23            
24             $self->log('Processing the DOAP Deps vocabulary');
25            
26             $self->cpanterms_deps;
27             $self->doap_deps;
28             $self->doap_deps_features;
29             };
30              
31              
32             sub cpanterms_deps
33             {
34 0     0 0   my $self = shift;
35            
36 0           my $meta = $self->metadata;
37 0           my $model = $self->model;
38 0           my $uri = 'RDF::Trine::Node::Resource'->new($self->project_uri);
39            
40 0           my @terms = qw(requires build_requires configure_requires test_requires recommends);
41 0           my %term_map = (
42             requires => [ 'runtime', 'requires' ],
43             build_requires => [ 'build', 'requires' ],
44             configure_requires => [ 'configure', 'requires' ],
45             test_requires => [ 'test', 'requires' ],
46             recommends => [ 'runtime', 'recommends' ],
47             );
48 0           foreach my $term (@terms)
49             {
50 0           my ($phase, $level) = @{$term_map{$term}};
  0            
51 0           my $Reqs;
52            
53 0           foreach my $dep ($model->objects($uri, $CPAN->$term))
54             {
55 0   0       $Reqs ||= 'CPAN::Meta::Requirements'->from_string_hash($meta->{prereqs}{$phase}{$level} || {});
      0        
56            
57 0           $self->log("WARNING: $term is deprecated in favour of http://ontologi.es/doap-deps#");
58 0 0         if ($dep->is_literal)
59             {
60 0           my ($mod, $ver) = split /\s+/, $dep->literal_value, 2;
61 0   0       $ver ||= 0;
62 1     1   413 no warnings;
  1         2  
  1         355  
63             $meta->{prereqs}{$phase}{$level}->add_string_requirement($mod, $ver)
64 0 0         unless $meta->{prereqs}{$phase}{$level}{$mod} > $ver;
65             }
66             else
67             {
68 0           $self->log("WARNING: Dunno what to do with ${dep}... we'll figure something out eventually.");
69             }
70             }
71            
72 0 0         $meta->{prereqs}{$phase}{$level} = $Reqs->as_string_hash if $Reqs;
73             }
74             }
75              
76             sub doap_deps
77             {
78 0     0 0   my $self = shift;
79            
80 0           my $meta = $self->metadata;
81 0           my $model = $self->model;
82 0           my $uri = 'RDF::Trine::Node::Resource'->new($self->project_uri);
83            
84 0           foreach my $phase (qw/ configure build test runtime develop /)
85             {
86 0           foreach my $level (qw/ requirement recommendation suggestion conflict /)
87             {
88 0           my $Reqs;
89            
90 0           my $term = "${phase}-${level}";
91             my $level2 = {
92             requirement => 'requires',
93             recommendation => 'recommends',
94             suggestion => 'suggests',
95             conflict => 'conflicts',
96 0           }->{$level};
97            
98 0           foreach my $dep ( $model->objects($uri, $DEPS->uri($term)) )
99             {
100 0   0       $Reqs ||= 'CPAN::Meta::Requirements'->from_string_hash($meta->{prereqs}{$phase}{$level2} || {});
      0        
101            
102 0 0         if ($dep->is_literal)
103             {
104 0           $self->log("WARNING: ". $DEPS->$term . " expects a resource, not literal $dep!");
105 0           next;
106             }
107            
108 0           foreach my $ident ( $model->objects($dep, $DEPS->on) )
109             {
110 0 0 0       unless ($ident->is_literal
      0        
111             and $ident->has_datatype
112             and $ident->literal_datatype eq $DEPS->CpanId->uri)
113             {
114 0           $self->log("WARNING: Dunno what to do with ${ident}... we'll figure something out eventually.");
115 0           next;
116             }
117            
118 0           my ($mod, $ver) = split /\s+/, $ident->literal_value, 2;
119 0   0       $ver ||= 0;
120 1     1   7 no warnings;
  1         2  
  1         719  
121 0           $Reqs->add_string_requirement($mod => $ver);
122            
123 0 0 0       if ($phase eq 'runtime' and $level eq 'conflict')
124             {
125 0           $meta->{x_breaks}{$mod} = $ver;
126             }
127             }
128             }
129            
130 0 0         $meta->{prereqs}{$phase}{$level2} = $Reqs->as_string_hash if $Reqs;
131             }
132             }
133             }
134              
135             sub doap_deps_features
136             {
137 0     0 0   my $self = shift;
138            
139 0           my $meta = $self->metadata;
140 0           my $model = $self->model;
141 0           my $uri = 'RDF::Trine::Node::Resource'->new($self->project_uri);
142            
143 0           my %F;
144            
145 0           foreach my $feature ($model->objects($uri, $DEPS->feature))
146             {
147 0           my %f;
148            
149 0           my ($label) =
150             map $_->literal_value,
151             grep $_->is_literal,
152             $model->objects($feature, $DOAP->name);
153 0           my ($desc) =
154             map $_->literal_value,
155             grep $_->is_literal,
156             $model->objects($feature, $DOAP->shortdesc);
157 0           my ($default) =
158             map $_->literal_value,
159             grep $_->is_literal,
160             $model->objects($feature, $DEPS->x_default);
161            
162 0 0         die "Feature defined with no name: $feature" unless defined $label;
163 0 0         $f{description} = $desc if defined $desc;
164 0   0       $f{x_default} = 0+!!( lc($default||'') eq 'true' );
165            
166 0           foreach my $phase (qw/ configure build test runtime develop /)
167             {
168 0           foreach my $level (qw/ requirement recommendation suggestion conflict /)
169             {
170 0           my $Reqs;
171            
172 0           my $term = "${phase}-${level}";
173             my $level2 = {
174             requirement => 'requires',
175             recommendation => 'recommends',
176             suggestion => 'suggests',
177             conflict => 'conflicts',
178 0           }->{$level};
179            
180 0           foreach my $dep ( $model->objects($feature, $DEPS->uri($term)) )
181             {
182 0   0       $Reqs ||= 'CPAN::Meta::Requirements'->from_string_hash($meta->{optional_features}{$label}{$phase}{$level2} || {});
      0        
183            
184 0 0         if ($dep->is_literal)
185             {
186 0           $self->log("WARNING: ". $DEPS->$term . " expects a resource, not literal $dep!");
187 0           next;
188             }
189            
190 0           foreach my $ident ( $model->objects($dep, $DEPS->on) )
191             {
192 0 0 0       unless ($ident->is_literal
      0        
193             and $ident->has_datatype
194             and $ident->literal_datatype eq $DEPS->CpanId->uri)
195             {
196 0           $self->log("WARNING: Dunno what to do with ${ident}... we'll figure something out eventually.");
197 0           next;
198             }
199            
200 0           my ($mod, $ver) = split /\s+/, $ident->literal_value, 2;
201 0   0       $ver ||= 0;
202 1     1   11 no warnings;
  1         3  
  1         141  
203 0           $Reqs->add_string_requirement($mod => $ver);
204             }
205             }
206            
207 0 0         $f{prereqs}{$phase}{$level2} = $Reqs->as_string_hash if $Reqs;
208             }
209             }
210            
211 0           $F{$label} = \%f;
212             }
213            
214 0           $meta->{optional_features} = \%F;
215             }
216              
217             1;