File Coverage

blib/lib/ODO/RDFS/Resource.pm
Criterion Covered Total %
statement 51 121 42.1
branch 12 68 17.6
condition 9 24 37.5
subroutine 10 13 76.9
pod 2 4 50.0
total 84 230 36.5


line stmt bran cond sub pod time code
1             package ODO::RDFS::Resource;
2              
3 3     3   4798 use strict;
  3         9  
  3         144  
4 3     3   19 use warnings;
  3         5  
  3         110  
5              
6 3     3   21 use vars qw( @ISA );
  3         7  
  3         167  
7 3     3   18 use vars qw /$VERSION/;
  3         6  
  3         289  
8             $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
9              
10 3     3   21 use ODO;
  3         5  
  3         162  
11 3     3   1381 use ODO::Query::Simple;
  3         19  
  3         202  
12 3     3   1351 use ODO::Statement::Group;
  3         6  
  3         132  
13 3     3   1807 use ODO::Ontology::RDFS::BaseClass;
  3         11  
  3         5126  
14              
15             @ISA = ( 'ODO::Ontology::RDFS::BaseClass', );
16              
17             #
18             # Description: The class resource, everything.
19             #
20             # Schema URI: http://www.w3.org/2000/01/rdf-schema#
21             #
22             sub new {
23 40     40 1 53 my $self = shift;
24 40         61 my ($resource, $graph, %properties) = @_;
25            
26 40         160 $self = $self->SUPER::new(@_);
27            
28             return undef
29 40 50       216 unless(ref $self);
30            
31 40         160 $self->propertyContainerName( 'ODO::RDFS::Resource::PropertiesContainer' );
32 40         425 $self->properties(bless {}, 'ODO::RDFS::Resource::PropertiesContainer');
33              
34 40         277 $self->properties()->{'parent'} = $self;
35              
36              
37              
38 40 50 33     254 if( exists($properties{'comment'})
39             && defined($properties{'comment'})) {
40            
41 0 0       0 unless(UNIVERSAL::isa($properties{'comment'}, 'ODO::RDFS::Properties::comment')) {
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('comment')) {
50 0         0 return undef;
51             }
52            
53 0         0 $self->properties()->comment( $properties{'comment'} );
54             }
55              
56              
57              
58 40 50 33     120 if( exists($properties{'label'})
59             && defined($properties{'label'})) {
60            
61 0 0       0 unless(UNIVERSAL::isa($properties{'label'}, 'ODO::RDFS::Properties::label')) {
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('label')) {
70 0         0 return undef;
71             }
72            
73 0         0 $self->properties()->label( $properties{'label'} );
74             }
75              
76              
77              
78 40 50 33     142 if( exists($properties{'member'})
79             && defined($properties{'member'})) {
80            
81 0 0       0 unless(UNIVERSAL::isa($properties{'member'}, 'ODO::RDFS::Properties::member')) {
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('member')) {
90 0         0 return undef;
91             }
92            
93 0         0 $self->properties()->member( $properties{'member'} );
94             }
95              
96              
97              
98 40 50 33     103 if( exists($properties{'seeAlso'})
99             && defined($properties{'seeAlso'})) {
100            
101 0 0       0 unless(UNIVERSAL::isa($properties{'seeAlso'}, 'ODO::RDFS::Properties::seeAlso')) {
102 0         0 return undef;
103             }
104            
105 0 0       0 unless($self->can('properties')) {
106 0         0 return undef;
107             }
108            
109 0 0       0 unless($self->properties()->can('seeAlso')) {
110 0         0 return undef;
111             }
112            
113 0         0 $self->properties()->seeAlso( $properties{'seeAlso'} );
114             }
115              
116              
117              
118 40 50 33     113 if( exists($properties{'isDefinedBy'})
119             && defined($properties{'isDefinedBy'})) {
120            
121 0 0       0 unless(UNIVERSAL::isa($properties{'isDefinedBy'}, 'ODO::RDFS::Properties::isDefinedBy')) {
122 0         0 return undef;
123             }
124            
125 0 0       0 unless($self->can('properties')) {
126 0         0 return undef;
127             }
128            
129 0 0       0 unless($self->properties()->can('isDefinedBy')) {
130 0         0 return undef;
131             }
132            
133 0         0 $self->properties()->isDefinedBy( $properties{'isDefinedBy'} );
134             }
135              
136              
137              
138 40 50 33     110 if( exists($properties{'type'})
139             && defined($properties{'type'})) {
140            
141 0 0       0 unless(UNIVERSAL::isa($properties{'type'}, 'ODO::RDFS::Properties::type')) {
142 0         0 return undef;
143             }
144            
145 0 0       0 unless($self->can('properties')) {
146 0         0 return undef;
147             }
148            
149 0 0       0 unless($self->properties()->can('type')) {
150 0         0 return undef;
151             }
152            
153 0         0 $self->properties()->type( $properties{'type'} );
154             }
155              
156              
157              
158 40 50 33     100 if( exists($properties{'value'})
159             && defined($properties{'value'})) {
160            
161 0 0       0 unless(UNIVERSAL::isa($properties{'value'}, 'ODO::RDFS::Properties::value')) {
162 0         0 return undef;
163             }
164            
165 0 0       0 unless($self->can('properties')) {
166 0         0 return undef;
167             }
168            
169 0 0       0 unless($self->properties()->can('value')) {
170 0         0 return undef;
171             }
172            
173 0         0 $self->properties()->value( $properties{'value'} );
174             }
175              
176              
177 40         112 return $self;
178             }
179              
180             sub queryString {
181 0     0 0 0 return '(?subj, rdf:type, )';
182             }
183              
184             sub objectURI {
185 0     0 0 0 return 'http://www.w3.org/2000/01/rdf-schema#Resource';
186             }
187              
188             sub value {
189 0     0 1 0 my $self = shift;
190            
191 0 0       0 return $self->subject()
192             if(UNIVERSAL::isa($self->subject(), 'ODO::Node::Literal'));
193            
194 0         0 return $self->__to_statement_array();
195             }
196              
197             sub __to_statement_array {
198 11     11   21 my $self = shift;
199            
200 11         20 my $statements = [];
201            
202 11         31 foreach my $my_super (@ISA) {
203            
204             next
205 11 50       91 unless(UNIVERSAL::can($my_super, '__to_statement_array'));
206            
207 0         0 my $super_func = "${my_super}::__to_statement_array";
208 0         0 push @{ $statements }, @{ $self->$super_func() };
  0         0  
  0         0  
209             }
210            
211 11         119 my %properties = (''=> '', 'comment'=> 'ODO::RDFS::Properties::comment', 'label'=> 'ODO::RDFS::Properties::label', 'member'=> 'ODO::RDFS::Properties::member', 'seeAlso'=> 'ODO::RDFS::Properties::seeAlso', 'isDefinedBy'=> 'ODO::RDFS::Properties::isDefinedBy', 'type'=> 'ODO::RDFS::Properties::type', 'value'=> 'ODO::RDFS::Properties::value', );
212            
213 11         36 foreach my $propertyName (keys(%properties)) {
214              
215             next
216 88 100 66     375 unless($propertyName && $propertyName ne '');
217            
218 77         74 my $property;
219 77         100 eval {$property = $self->properties()->$propertyName()};
  77         487  
220 77 50       258 next unless $@;
221            
222 0         0 foreach my $p (@{ $property }) {
  0         0  
223 0         0 my $p_value = $p->value();
224            
225 0         0 my $property_uri = ODO::Node::Resource->new($properties{$propertyName}->objectURI() );
226 0 0       0 if(UNIVERSAL::isa($p_value, 'ODO::Node::Literal')) {
227 0         0 push @{ $statements }, ODO::Statement->new($self->subject(), $property_uri, $p_value);
  0         0  
228             }
229             else {
230 0         0 push @{ $statements }, ODO::Statement->new($self->subject(), $property_uri, $p->subject());
  0         0  
231 0         0 push @{ $statements }, @{ $p_value };
  0         0  
  0         0  
232             }
233             }
234             }
235            
236 11         103 return $statements;
237             }
238              
239             1;