| 1 | package RDF::DOAP::Resource; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.105'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use RDF::DOAP::Types -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use RDF::DOAP::Utils -traits; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Scalar::Util qw( weaken refaddr ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use RDF::Trine::Namespace qw(rdf rdfs owl xsd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has rdf_about => ( | |||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | isa => Identifier, | ||||||||||||||||||||||||||||
| 18 | coerce => 1, | ||||||||||||||||||||||||||||
| 19 | predicate => 'has_rdf_about', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | has rdf_model => ( | |||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | isa => Model, | ||||||||||||||||||||||||||||
| 25 | predicate => 'has_rdf_model', | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | has rdf_type => ( | ||||||||||||||||||||||||||||
| 29 | traits => [ WithURI ], | ||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | isa => ArrayRef[Identifier], | ||||||||||||||||||||||||||||
| 32 | coerce => 1, | ||||||||||||||||||||||||||||
| 33 | uri => $rdf->type, | ||||||||||||||||||||||||||||
| 34 | multi => 1, | ||||||||||||||||||||||||||||
| 35 | 9 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | has $_ => ( | ||||||||||||||||||||||||||||
| 39 | traits => [ WithURI ], | ||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => String, | ||||||||||||||||||||||||||||
| 42 | coerce => 1, | ||||||||||||||||||||||||||||
| 43 | uri => $rdfs->$_, | ||||||||||||||||||||||||||||
| 44 | 2 | ) for qw( label comment ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | has see_also => ( | ||||||||||||||||||||||||||||
| 47 | traits => [ WithURI ], | ||||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||
| 49 | isa => ArrayRef[Identifier], | ||||||||||||||||||||||||||||
| 50 | coerce => 1, | ||||||||||||||||||||||||||||
| 51 | uri => $rdfs->seeAlso, | ||||||||||||||||||||||||||||
| 52 | multi => 1, | ||||||||||||||||||||||||||||
| 53 | lazy => 1, | ||||||||||||||||||||||||||||
| 54 | 10 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||
| 55 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 10 | ▶ | if ($self->has_rdf_about && $self->rdf_about =~ /^tdb:[^:]*:(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_rdf_about and $self->rdf_about =~ /^tdb:[^:]*:(.*)$/
MC/DC0%0/2
$self->has_rdf_about and $self->rdf_about =~ /^tdb:[^:]*:(.*)$/
$self->has_rdf_about
$self->rdf_about =~ /^tdb:[^:]*:(.*)$/
Truth table33%1/3
A and B
A= $self->has_rdf_aboutB= $self->rdf_about =~ /^tdb:[^:]*:(.*)$/
| |||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 0 | return [ Identifier->coerce($1) ]; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 10 | return []; | |||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||
| 62 | 2 | ); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | our $MODEL; | |||||||||||||||||||||||||||
| 65 | 2 | my %objects; | |||||||||||||||||||||||||||
| 66 | sub rdf_load | ||||||||||||||||||||||||||||
| 67 | 42 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rdf_load: called CC=12 SCAR=25.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 42 | my $class = shift; | |||||||||||||||||||||||||||
| 69 | 42 | my $identifier = Identifier->assert_coerce( $_[0] ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 42 | ▶ | my $model = $_[1] ? Model->assert_return( $_[1] ) : $MODEL or die; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | return $objects{ refaddr($model) }{ $identifier } | ||||||||||||||||||||||||||||
| 74 | 42 | ▶ | if $objects{ refaddr($model) }{ $identifier }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 32 | my (%attr, %multi); | |||||||||||||||||||||||||||
| 77 | 32 | for my $a ($class->meta->get_all_attributes) | |||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 346 | ▶ | $a->does(WithURI) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 262 | ▶ | $attr{ $a->uri } = $a->init_arg || $a->name; | ||||||||||||||||||||||||||
|
Condition33%1/3
$a->init_arg || $a->name
MC/DC0%0/2
$a->init_arg || $a->name
$a->init_arg
$a->name
Truth table33%1/3
A || B
A= $a->init_argB= $a->name
| |||||||||||||||||||||||||||||
| 81 | 262 | $multi{ $a->uri } = $a->multi; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 32 | my %args = ( | |||||||||||||||||||||||||||
| 85 | rdf_about => $identifier, | ||||||||||||||||||||||||||||
| 86 | rdf_model => $model, | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | 32 | my $iter = $model->get_statements($identifier, undef, undef); | |||||||||||||||||||||||||||
| 89 | 32 | ▶ | while (my $st = $iter->next) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 138 | ▶ | my $name = $attr{ $st->predicate } or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 111 | ▶ | if ($multi{ $st->predicate }) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 58 | ▶ | push @{ $args{$name} ||= [] }, $st->object; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{$name} ||= []
MC/DC100%1/1
$args{$name} ||= []
$args{$name}
Truth table100%2/2
A
A= $args{$name}
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 53 | ▶ | $args{$name} ||= $st->object; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{$name} ||= $st->object
MC/DC0%0/2
$args{$name} ||= $st->object
$args{$name}
$st->object
Truth table33%1/3
A ||= B
A= $args{$name}B= $st->object
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 32 | local $MODEL = $model; | |||||||||||||||||||||||||||
| 104 | 32 | my $self = $objects{ refaddr($model) }{ $identifier } = $class->new(%args); | |||||||||||||||||||||||||||
| 105 | 32 | weaken($objects{ refaddr($model) }{ $identifier }); | |||||||||||||||||||||||||||
| 106 | 32 | return $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub rdf_get | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rdf_get: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | croak "This object cannot rdf_get; stopped" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_rdf_model and $self->has_rdf_about
MC/DC0%0/2
$self->has_rdf_model and $self->has_rdf_about
$self->has_rdf_model
$self->has_rdf_about
Truth table0%0/3
A and B
A= $self->has_rdf_modelB= $self->has_rdf_about
| |||||||||||||||||||||||||||||
| 113 | unless $self->has_rdf_model && $self->has_rdf_about; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my @values = $self->rdf_model->objects_for_predicate_list($self->rdf_about, @_); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | wantarray ? @values : $values[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub rdf_get_literal | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rdf_get_literal: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 0 | my @values = grep $_->is_literal, $self->rdf_get(@_); | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | wantarray ? @values : $values[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | sub rdf_get_uri | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rdf_get_uri: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 129 | 0 | my @values = grep $_->is_resource, $self->rdf_get(@_); | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | wantarray ? @values : $values[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub TO_JSON | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
TO_JSON: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | $self->fixes if $self->can('fixes'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | my $hash = +{ %$self }; | |||||||||||||||||||||||||||
| 138 | 0 | delete $hash->{$_} for qw( rdf_about rdf_model ); | |||||||||||||||||||||||||||
| 139 | 0 | for my $k (keys %$hash) { | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (blessed $hash->{$k} and $hash->{$k}->isa('RDF::Trine::Node')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($hash->{$k}) and $hash->{$k}->isa("RDF::Trine::Node")
MC/DC0%0/2
builtin::blessed($hash->{$k}) and $hash->{$k}->isa("RDF::Trine::Node")
builtin::blessed($hash->{$k})
$hash->{$k}->isa("RDF::Trine::Node")
Truth table0%0/3
A and B
A= builtin::blessed($hash->{$k})B= $hash->{$k}->isa("RDF::Trine::Node")
| |||||||||||||||||||||||||||||
| 141 | 0 | $hash->{$k} = $hash->{$k}->as_ntriples; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (ref $hash->{$k} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | $hash->{$k} = [ map { | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | (blessed $_ and $_->isa('RDF::Trine::Node')) ? $_->as_ntriples : $_ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($_) and $_->isa("RDF::Trine::Node")
MC/DC0%0/2
builtin::blessed($_) and $_->isa("RDF::Trine::Node")
builtin::blessed($_)
$_->isa("RDF::Trine::Node")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->isa("RDF::Trine::Node")
| |||||||||||||||||||||||||||||
| 146 | 0 | } @{ $hash->{$k} } ]; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $hash->{'@'} = $self->rdf_about->as_ntriples if $self->has_rdf_about; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | # $hash->{__ISA__} = [ $self->meta->linearized_isa ]; | ||||||||||||||||||||||||||||
| 151 | # $hash->{__DOES__} = [ map $_->name, $self->meta->calculate_all_roles_with_inheritance ]; | ||||||||||||||||||||||||||||
| 152 | 0 | return $hash; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub dump_json | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dump_json: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 0 | require JSON; | |||||||||||||||||||||||||||
| 158 | 0 | JSON::to_json( | |||||||||||||||||||||||||||
| 159 | shift(), | ||||||||||||||||||||||||||||
| 160 | { pretty => 1, canonical => 1, convert_blessed => 1 }, | ||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | sub isa | ||||||||||||||||||||||||||||
| 165 | 193 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isa: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 193 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 193 | ▶ | return grep($_[0]->equal($_), @{$self->rdf_type}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | if Identifier->check(@_); | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 139 | $self->SUPER::isa(@_); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 2 | 1; | |||||||||||||||||||||||||||