File Coverage

blib/lib/ODO/Node.pm
Criterion Covered Total %
statement 129 130 99.2
branch 8 10 80.0
condition 2 6 33.3
subroutine 41 42 97.6
pod 4 4 100.0
total 184 192 95.8


line stmt bran cond sub pod time code
1             #
2             # Copyright (c) 2004-2006 IBM Corporation.
3             #
4             # All rights reserved. This program and the accompanying materials
5             # are made available under the terms of the Eclipse Public License v1.0
6             # which accompanies this distribution, and is available at
7             # http://www.eclipse.org/legal/epl-v10.html
8             #
9             # File: $Source: /var/lib/cvs/ODO/lib/ODO/Node.pm,v $
10             # Created by: Stephen Evanchik( evanchik@us.ibm.com )
11             # Created on: 11/02/2004
12             # Revision: $Id: Node.pm,v 1.4 2010-02-17 17:20:23 ubuntu Exp $
13             #
14             # Contributors:
15             # IBM Corporation - initial API and implementation
16             #
17             package ODO::Node;
18              
19 15     15   170445 use strict;
  15         33  
  15         597  
20 15     15   78 use warnings;
  15         33  
  15         413  
21              
22 15     15   79 use base qw/ODO/;
  15         24  
  15         2974  
23              
24 15     15   131 use Digest::MD5 qw/md5_hex/;
  15         31  
  15         738  
25              
26 15     15   83 use vars qw /$VERSION/;
  15         30  
  15         6113  
27             $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
28              
29             __PACKAGE__->mk_accessors(qw/value/);
30              
31             =head1 NAME
32              
33             ODO::Node
34              
35             =head1 SYNOPSIS
36              
37             use ODO::Node;
38              
39             # Classes within this package:
40             #
41             # ODO::Node
42             # ODO::Node::Literal
43             # ODO::Node::Resource
44             # ODO::Node::Blank
45             # ODO::Node::Variable
46             # ODO::Node::Any
47              
48             =head1 DESCRIPTION
49              
50             Description.
51              
52             =head1 CONSTRUCTOR
53              
54             Constructor.
55              
56             =cut
57              
58             sub new {
59 703     703 1 2763 my $self = shift;
60 703         1051 my ($node) = @_;
61              
62 703 50 33     2515 return $node
63             if( scalar(@_) == 1
64             && $node->isa( ref $self )
65             );
66             #&& UNIVERSAL::isa($node, $self));
67            
68 703         2860 return $self->SUPER::new(@_);
69             }
70              
71             =head1 ODO::Node
72              
73             =head2 DESCRIPTION
74              
75             The base class for all node types.
76              
77             =head2 METHODS
78              
79             =over
80              
81             =item value( [ $value ] )
82              
83             Manipulates the actual value of the object (resource or literal).
84              
85             Parameters:
86             $value - Optional. If set, the value will be set to the given parameter.
87              
88             Returns:
89             The value stored by this object.
90              
91             =item equal( $node )
92              
93             Determines whether the node is the same as the node passed
94             to this function
95              
96             =cut
97              
98             sub equal {
99 1378     1378 1 10348 my ($self, $this_node) = @_;
100              
101 1378 50 33     12954 return 1
102             if( $this_node->isa('ODO::Node::Any') # UNIVERSAL::isa($this_node, 'ODO::Node::Any')
103             || $self->isa('ODO::Node::Any') # UNIVERSAL::isa($self, 'ODO::Node::Any')
104             );
105            
106 1378 100       2414 return ($this_node->hash() eq $self->hash()) ? 1 : 0;
107             }
108              
109             =item hash( )
110              
111             =cut
112              
113             sub hash {
114 2822     2822 1 3119 my $self = shift;
115              
116 2822 100       6058 if(!defined($self->{'_hash_value'})) {
117 172         415 $self->{'_hash_value'} = md5_hex($self->value());
118             }
119            
120 2822         11221 return $self->{'_hash_value'};
121             }
122              
123              
124             sub init {
125 706     706 1 15689 my ($self, $config) = @_;
126            
127 706 100       5364 return $config->{'value'}
128             if(UNIVERSAL::isa($config->{'value'}, ref $self));
129            
130 705         2685 $self->params($config, qw/value/);
131 705         22316 return $self;
132             }
133              
134              
135             =back
136              
137             =cut
138              
139              
140             package ODO::Node::Literal;
141              
142 15     15   116 use strict;
  15         27  
  15         549  
143 15     15   105 use warnings;
  15         30  
  15         3269  
144              
145             our @ISA = ('ODO::Node');
146              
147             __PACKAGE__->mk_accessors(qw/language datatype/);
148              
149             =head1 ODO::Node::Literal
150              
151             =head2 DESCRIPTION
152              
153             Literal node type.
154              
155             =head2 METHODS
156              
157             =over
158              
159             =item new( $value, $language, $datatype )
160              
161             Create a new literal node with the specified value and optional language and datatype.
162              
163             =cut
164              
165             sub new {
166 51     51   123924 my $self = shift;
167 51         567 my $params = $self->params_to_hash(\@_, 1, [qw/value language datatype/], { 'literal'=> 'value' } );
168 51         3375 return $self->SUPER::new(%{ $params });
  51         311  
169             }
170              
171              
172             =item language( [ $language ] )
173              
174             Get or set the language element of the node.
175              
176             =item datatype( [ $datatype ] )
177              
178             Get or set the datatype element of the node.
179              
180             =cut
181              
182             sub init {
183 51     51   1393 my ($self, $config) = @_;
184 51         167 $self = $self->SUPER::init($config);
185 51         186 $self->params($config, qw/language datatype/);
186 51         1699 return $self;
187             }
188              
189              
190             =back
191              
192             =cut
193              
194             package ODO::Node::Resource;
195              
196 15     15   243 use strict;
  15         33  
  15         494  
197 15     15   72 use warnings;
  15         39  
  15         2006  
198              
199             our @ISA = ('ODO::Node');
200              
201             =head1 ODO::Node::Resource
202              
203             =head2 DESCRIPTION
204              
205             The URI / resource node type.
206              
207             =head2 METHODS
208              
209             =over
210              
211             =item new( $uri_value )
212              
213             =cut
214              
215             sub new {
216 557     557   448109 my $self = shift;
217 557         3451 my $params = $self->params_to_hash(\@_, 1, [qw/value/], { 'uri' => 'value' } );
218 557         20741 return $self->SUPER::new(%{ $params });
  557         2593  
219             }
220              
221             =item uri()
222              
223             Alias for OOD::Node::value
224              
225             =cut
226              
227 15     15   82 no strict;
  15         89  
  15         435  
228 15     15   85 no warnings;
  15         25  
  15         865  
229              
230             *uri = \&ODO::Node::value;
231              
232 15     15   113 use strict;
  15         31  
  15         433  
233 15     15   78 use warnings;
  15         22  
  15         538  
234              
235              
236             =back
237              
238             =cut
239              
240              
241             package ODO::Node::Blank;
242              
243 15     15   77 use strict;
  15         93  
  15         400  
244 15     15   77 use warnings;
  15         38  
  15         1684  
245              
246             our @ISA = ('ODO::Node::Resource');
247              
248             =head1 ODO::Node::Blank
249              
250             =head2 DESCRIPTION
251              
252             The blank node type.
253              
254             =head2 METHODS
255              
256             =over
257              
258             =item new( [ $value ] )
259              
260             Create a new blank node with the specified value.
261              
262             =cut
263              
264             sub new {
265 3     3   2976 my $self = shift;
266 3         45 my $params = $self->params_to_hash(\@_, 1, [qw/value/], { 'node_id' => 'value' } );
267 3         223 return $self->Class::Base::new(%{ $params });
  3         24  
268             }
269              
270             =item node_id( [ $value ] )
271              
272             Alias for SUPER::value
273              
274             =cut
275              
276 15     15   81 no strict;
  15         23  
  15         1828  
277 15     15   73 no warnings;
  15         21  
  15         622  
278              
279             *node_id = \&ODO::Node::value;
280              
281 15     15   79 use strict;
  15         30  
  15         424  
282 15     15   66 use warnings;
  15         31  
  15         545  
283              
284             =back
285              
286             =cut
287              
288             package ODO::Node::Variable;
289              
290 15     15   75 use strict;
  15         32  
  15         407  
291 15     15   71 use warnings;
  15         22  
  15         1846  
292              
293             our @ISA = ('ODO::Node');
294              
295             =head1 ODO::Node::Variable
296              
297             =head2 DESCRIPTION
298              
299             The variable node type.
300              
301             =head2 METHODS
302              
303             =over
304              
305             =item new( $name_val | name=> $name_val )
306              
307             =cut
308              
309             sub new {
310 80     80   225661 my $self = shift;
311 80         747 my $params = $self->params_to_hash(\@_, 1, [qw/value/], { 'name' => 'value' } );
312 80         5461 return $self->SUPER::new(%{ $params });
  80         520  
313             }
314              
315             =item name()
316              
317             Alias for SUPER::value
318              
319             =cut
320              
321 15     15   90 no strict;
  15         29  
  15         412  
322 15     15   72 no warnings;
  15         22  
  15         881  
323              
324             *name = \&ODO::Node::value;
325              
326 15     15   71 use strict;
  15         27  
  15         406  
327 15     15   69 use warnings;
  15         91  
  15         496  
328              
329              
330             =back
331              
332             =cut
333              
334             package ODO::Node::Any;
335              
336 15     15   70 use strict;
  15         26  
  15         490  
337 15     15   81 use warnings;
  15         36  
  15         1332  
338              
339             our @ISA = ('ODO::Node');
340              
341             =head1 ODO::Node::Any
342              
343             =head2 DESCRIPTION
344              
345             The node that matches any node.
346              
347             =head2 METHODS
348              
349             =over
350              
351             =item value()
352              
353             ANY nodes don't have a value
354              
355             =cut
356              
357             sub value {
358 0     0   0 return undef;
359             }
360              
361             =item equal( $node )
362              
363             The ANY node type is equal to everything
364              
365             =cut
366              
367             sub equal {
368 38     38   426 return 1;
369             }
370              
371             =item $ODO::Node::ANY
372              
373             =cut
374              
375 15     15   74 no warnings;
  15         31  
  15         781  
376              
377             $ODO::Node::ANY = ODO::Node::Any->new();
378              
379 15     15   81 use warnings;
  15         32  
  15         657  
380              
381              
382             =back
383              
384             =cut
385              
386             package ODO::Node::Constants;
387              
388 15     15   69 use strict;
  15         24  
  15         441  
389 15     15   94 use warnings;
  15         23  
  15         1025  
390              
391             =head1 ODO::Node::Constants
392              
393             =head2 DESCRIPTION
394              
395             Constants that can be used by the node subsystem.
396              
397             =head2 CONSTANTS
398              
399             =head3 URI Regular Expression
400              
401             =over
402              
403             =item Official URI regular expression
404              
405             $URI =~ ^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?
406              
407             =cut
408              
409             our $URI_REGEXP = '^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?';
410              
411             =back
412              
413             =head1 AUTHOR
414              
415             IBM Corporation
416              
417             =head1 SEE ALSO
418              
419             L, L
420              
421             =head1 COPYRIGHT
422              
423             Copyright (c) 2004-2006 IBM Corporation.
424              
425             All rights reserved. This program and the accompanying materials
426             are made available under the terms of the Eclipse Public License v1.0
427             which accompanies this distribution, and is available at
428             http://www.eclipse.org/legal/epl-v10.html
429              
430              
431             =cut
432              
433              
434             1;
435              
436             __END__