File Coverage

blib/lib/Dist/Inkt/Role/DetermineRightsFromRdf.pm
Criterion Covered Total %
statement 30 43 69.7
branch 0 8 0.0
condition n/a
subroutine 10 11 90.9
pod n/a
total 40 62 64.5


line stmt bran cond sub pod time code
1             package Dist::Inkt::Role::DetermineRightsFromRdf;
2              
3             our $AUTHORITY = 'cpan:TOBYINK';
4             our $VERSION = '0.022';
5              
6 1     1   1267 use Moose::Role;
  1         3  
  1         8  
7 1     1   5317 use RDF::Trine qw( iri literal statement variable );
  1         3  
  1         67  
8 1     1   7 use List::MoreUtils qw( uniq );
  1         3  
  1         8  
9 1     1   513 use Path::Tiny qw( path );
  1         25  
  1         43  
10 1     1   6 use Path::Iterator::Rule;
  1         2  
  1         24  
11 1     1   5 use Software::License;
  1         2  
  1         19  
12 1     1   8 use Software::LicenseUtils;
  1         3  
  1         44  
13 1     1   6 use Types::Standard -types;
  1         2  
  1         9  
14 1     1   4318 use namespace::autoclean;
  1         4  
  1         10  
15              
16             my %URIS = (
17             'http://www.gnu.org/licenses/agpl-3.0.txt' => 'AGPL_3',
18             'http://www.apache.org/licenses/LICENSE-1.1' => 'Apache_1_1',
19             'http://www.apache.org/licenses/LICENSE-2.0' => 'Apache_2_0',
20             'http://www.apache.org/licenses/LICENSE-2.0.txt' => 'Apache_2_0',
21             'http://www.perlfoundation.org/artistic_license_1_0' => 'Artistic_1_0',
22             'http://opensource.org/licenses/artistic-license.php' => 'Artistic_1_0',
23             'http://www.perlfoundation.org/artistic_license_2_0' => 'Artistic_2_0',
24             'http://opensource.org/licenses/artistic-license-2.0.php' => 'Artistic_2_0',
25             'http://www.opensource.org/licenses/bsd-license.php' => 'BSD',
26             'http://creativecommons.org/publicdomain/zero/1.0/' => 'CC0_1_0',
27             'http://www.freebsd.org/copyright/freebsd-license.html' => 'FreeBSD',
28             'http://www.gnu.org/copyleft/fdl.html' => 'GFDL_1_3',
29             'http://www.opensource.org/licenses/gpl-license.php' => 'GPL_1',
30             'http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt' => 'GPL_1',
31             'http://www.opensource.org/licenses/gpl-2.0.php' => 'GPL_2',
32             'http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt' => 'GPL_2',
33             'http://www.opensource.org/licenses/gpl-3.0.html' => 'GPL_3',
34             'http://www.gnu.org/licenses/gpl-3.0.txt' => 'GPL_3',
35             'http://www.opensource.org/licenses/lgpl-2.1.php' => 'LGPL_2_1',
36             'http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' => 'LGPL_2_1',
37             'http://www.opensource.org/licenses/lgpl-3.0.html' => 'LGPL_3_0',
38             'http://www.gnu.org/licenses/lgpl-3.0.txt' => 'LGPL_3_0',
39             'http://www.opensource.org/licenses/mit-license.php' => 'MIT',
40             'http://www.mozilla.org/MPL/MPL-1.0.txt' => 'Mozilla_1_0',
41             'http://www.mozilla.org/MPL/MPL-1.1.txt' => 'Mozilla_1_1',
42             'http://opensource.org/licenses/mozilla1.1.php' => 'Mozilla_1_1',
43             'http://www.openssl.org/source/license.html' => 'OpenSSL',
44             'http://dev.perl.org/licenses/' => 'Perl_5',
45             'http://www.opensource.org/licenses/postgresql' => 'PostgreSQL',
46             'http://trolltech.com/products/qt/licenses/licensing/qpl' => 'QPL_1_0',
47             'http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html' => 'SSLeay',
48             'http://www.openoffice.org/licenses/sissl_license.html' => 'Sun',
49             'http://www.zlib.net/zlib_license.html' => 'Zlib',
50             );
51             eval("require Software::License::$_") for uniq values %URIS;
52              
53 1     1   259 use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
  1         5  
  1         9  
54             my $CPAN = RDF::Trine::Namespace->new('http://purl.org/NET/cpan-uri/terms#');
55             my $DC = RDF::Trine::Namespace->new('http://purl.org/dc/terms/');
56             my $DOAP = RDF::Trine::Namespace->new('http://usefulinc.com/ns/doap#');
57             my $FOAF = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/');
58             my $NFO = RDF::Trine::Namespace->new('http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#');
59             my $SKOS = RDF::Trine::Namespace->new('http://www.w3.org/2004/02/skos/core#');
60              
61             sub _determine_rights_from_rdf
62             {
63 0     0     my ($self, $f) = @_;
64 0 0         unless ($self->{_rdf_copyright_data})
65             {
66 0           my $model = $self->model;
67 0           my $iter = $model->get_pattern(
68             RDF::Trine::Pattern->new(
69             statement(variable('subject'), $NFO->fileName, variable('filename')),
70             statement(variable('subject'), $DC->license, variable('license')),
71             statement(variable('subject'), $DC->rightsHolder, variable('rights_holder')),
72             statement(variable('rights_holder'), $FOAF->name, variable('name')),
73             ),
74             );
75 0           my %results;
76 0           while (my $row = $iter->next) {
77 0           my $l = $row->{license}->uri;
78             $row->{class} = literal("Software::License::$URIS{$l}")
79 0 0         if exists $URIS{$l};
80 0           $results{ $row->{filename}->literal_value } = $row;
81             }
82 0           $self->{_rdf_copyright_data} = \%results;
83             }
84            
85 0 0         if ( my $row = $self->{_rdf_copyright_data}{$f} ) {
86             return (
87             sprintf("Copyright %d %s.", 1900 + (localtime((stat $f)[9]))[5], $row->{name}->literal_value),
88             $row->{class}->literal_value->new({holder => "the copyright holder(s)"}),
89 0 0         ) if $row->{class};
90             }
91            
92 0           return;
93             }
94              
95             1;