Role/AddExternalRDF.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 66 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Dist::Inkt::Role::AddExternalRDF;
2  
3 our $AUTHORITY = 'cpan:KJETILK';
4 our $VERSION = '0.110';
5  
6 use Moose::Role;
7 use namespace::autoclean;
8 use RDF::Trine::Parser;
9 use Path::Tiny;
10  
11 with 'Dist::Inkt::Role::RDFModel';
12  
13 after PopulateModel => sub {
14 my $self = shift;
15  
16 my $justaddfile = path($ENV{'DIST_INKT_ADD_DATA'} || "~/.dist-inkt-data.ttl");
17 my $filteredfile = path($ENV{'DIST_INKT_FILTERED_DATA'} || "~/.dist-inkt-filtered-data.ttl");
18 my $base_uri = sprintf('http://purl.org/NET/cpan-uri/dist/%s/', $self->name);
19  
20 if ($justaddfile->is_file) {
21 $self->log('Reading %s', $justaddfile);
22
23 my $p = RDF::Trine::Parser->guess_parser_by_filename($justaddfile->basename);
24 $p->parse_file_into_model($base_uri, $justaddfile->filehandle, $self->model);
25 }
26
27 if ($filteredfile->is_file) {
28 $self->log('Reading %s', $filteredfile);
29 my %resources;
30 my $iter = $self->model->as_stream;
31 while (my $st = $iter->next) {
32 if ($st->subject->is_resource) {
33 $resources{$st->subject->uri_value} = 1;
34 }
35 if ($st->predicate->is_resource) {
36 $resources{$st->predicate->uri_value} = 1;
37 }
38 if ($st->object->is_resource) {
39 $resources{$st->object->uri_value} = 1;
40 }
41 }
42 my $proto = RDF::Trine::Parser->guess_parser_by_filename($filteredfile->basename);
43 my $p = $proto->new;
44 my $handler = sub {
45 my $st = shift;
46 if ($resources{$st->subject->uri_value}) {
47 $self->model->add_statement( $st );
48 }
49 };
50 $p->parse_file($base_uri, $filteredfile->filehandle, $handler);
51 }
52
53 };
54  
55 1;
56  
57 __END__