File Coverage

blib/lib/ODO/RDFS/Property.pm
Criterion Covered Total %
statement 50 86 58.1
branch 7 34 20.5
condition 5 12 41.6
subroutine 10 13 76.9
pod 2 4 50.0
total 74 149 49.6


line stmt bran cond sub pod time code
1             package ODO::RDFS::Property;
2              
3 1     1   4 use strict;
  1         1  
  1         26  
4 1     1   6 use warnings;
  1         2  
  1         25  
5              
6 1     1   5 use vars qw( @ISA );
  1         2  
  1         36  
7 1     1   4 use vars qw /$VERSION/;
  1         2  
  1         97  
8             $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/;
9              
10 1     1   5 use ODO;
  1         3  
  1         30  
11 1     1   5 use ODO::Query::Simple;
  1         2  
  1         38  
12 1     1   6 use ODO::Statement::Group;
  1         2  
  1         31  
13 1     1   5 use ODO::RDFS::Resource;
  1         3  
  1         768  
14              
15             @ISA = ( 'ODO::RDFS::Resource', );
16              
17             #
18             # Description: The class of RDF properties.
19             #
20             # Schema URI: http://www.w3.org/1999/02/22-rdf-syntax-ns#
21             #
22             sub new {
23 32     32 1 49 my $self = shift;
24 32         60 my ($resource, $graph, %properties) = @_;
25            
26 32         134 $self = $self->SUPER::new(@_);
27            
28             return undef
29 32 50       78 unless(ref $self);
30            
31 32         76 $self->propertyContainerName( 'ODO::RDFS::Property::PropertiesContainer' );
32 32         267 $self->properties(bless {}, 'ODO::RDFS::Property::PropertiesContainer');
33              
34 32         209 $self->properties()->{'parent'} = $self;
35              
36              
37              
38 32 50 33     202 if( exists($properties{'subPropertyOf'})
39             && defined($properties{'subPropertyOf'})) {
40            
41 0 0       0 unless(UNIVERSAL::isa($properties{'subPropertyOf'}, 'ODO::RDFS::Properties::subPropertyOf')) {
42 0         0 return undef;
43             }
44            
45 0 0       0 unless($self->can('properties')) {
46 0         0 return undef;
47             }
48            
49 0 0       0 unless($self->properties()->can('subPropertyOf')) {
50 0         0 return undef;
51             }
52            
53 0         0 $self->properties()->subPropertyOf( $properties{'subPropertyOf'} );
54             }
55              
56              
57              
58 32 50 33     171 if( exists($properties{'range'})
59             && defined($properties{'range'})) {
60            
61 0 0       0 unless(UNIVERSAL::isa($properties{'range'}, 'ODO::RDFS::Properties::range')) {
62 0         0 return undef;
63             }
64            
65 0 0       0 unless($self->can('properties')) {
66 0         0 return undef;
67             }
68            
69 0 0       0 unless($self->properties()->can('range')) {
70 0         0 return undef;
71             }
72            
73 0         0 $self->properties()->range( $properties{'range'} );
74             }
75              
76              
77              
78 32 50 33     76 if( exists($properties{'domain'})
79             && defined($properties{'domain'})) {
80            
81 0 0       0 unless(UNIVERSAL::isa($properties{'domain'}, 'ODO::RDFS::Properties::domain')) {
82 0         0 return undef;
83             }
84            
85 0 0       0 unless($self->can('properties')) {
86 0         0 return undef;
87             }
88            
89 0 0       0 unless($self->properties()->can('domain')) {
90 0         0 return undef;
91             }
92            
93 0         0 $self->properties()->domain( $properties{'domain'} );
94             }
95              
96              
97 32         102 return $self;
98             }
99              
100             sub queryString {
101 0     0 0 0 return '(?subj, rdf:type, )';
102             }
103              
104             sub objectURI {
105 0     0 0 0 return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property';
106             }
107              
108             sub value {
109 0     0 1 0 my $self = shift;
110            
111 0 0       0 return $self->subject()
112             if(UNIVERSAL::isa($self->subject(), 'ODO::Node::Literal'));
113            
114 0         0 return $self->__to_statement_array();
115             }
116              
117             sub __to_statement_array {
118 5     5   14 my $self = shift;
119            
120 5         12 my $statements = [];
121            
122 5         20 foreach my $my_super (@ISA) {
123            
124             next
125 5 50       42 unless(UNIVERSAL::can($my_super, '__to_statement_array'));
126            
127 5         18 my $super_func = "${my_super}::__to_statement_array";
128 5         49 push @{ $statements }, @{ $self->$super_func() };
  5         12  
  5         26  
129             }
130            
131 5         34 my %properties = (''=> '', 'subPropertyOf'=> 'ODO::RDFS::Properties::subPropertyOf', 'range'=> 'ODO::RDFS::Properties::range', 'domain'=> 'ODO::RDFS::Properties::domain', );
132            
133 5         16 foreach my $propertyName (keys(%properties)) {
134              
135             next
136 20 100 66     90 unless($propertyName && $propertyName ne '');
137            
138 15         43 my $property = $self->properties()->$propertyName();
139            
140 15         29 foreach my $p (@{ $property }) {
  15         50  
141 0         0 my $p_value = $p->value();
142            
143 0         0 my $property_uri = ODO::Node::Resource->new($properties{$propertyName}->objectURI() );
144 0 0       0 if(UNIVERSAL::isa($p_value, 'ODO::Node::Literal')) {
145 0         0 push @{ $statements }, ODO::Statement->new($self->subject(), $property_uri, $p_value);
  0         0  
146             }
147             else {
148 0         0 push @{ $statements }, ODO::Statement->new($self->subject(), $property_uri, $p->subject());
  0         0  
149 0         0 push @{ $statements }, @{ $p_value };
  0         0  
  0         0  
150             }
151             }
152             }
153            
154 5         46 return $statements;
155             }
156              
157             1;