File Coverage

blib/lib/RDF/Trine/Node/Variable.pm
Criterion Covered Total %
statement 44 49 89.8
branch 4 4 100.0
condition 3 3 100.0
subroutine 17 19 89.4
pod 8 8 100.0
total 76 83 91.5


line stmt bran cond sub pod time code
1             # RDF::Trine::Node::Variable
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Trine::Node::Variable - RDF Node class for variables
7              
8             =head1 VERSION
9              
10             This document describes RDF::Trine::Node::Variable version 1.017
11              
12             =cut
13              
14             package RDF::Trine::Node::Variable;
15              
16 68     68   441 use strict;
  68         160  
  68         1788  
17 68     68   338 use warnings;
  68         146  
  68         1619  
18 68     68   321 no warnings 'redefine';
  68         139  
  68         2434  
19 68     68   356 use base qw(RDF::Trine::Node);
  68         146  
  68         5518  
20              
21 68     68   453 use Data::Dumper;
  68         160  
  68         2657  
22 68     68   386 use Scalar::Util qw(blessed);
  68         156  
  68         2556  
23 68     68   368 use Carp qw(carp croak confess);
  68         152  
  68         3753  
24              
25             ######################################################################
26              
27             our ($VERSION);
28             BEGIN {
29 68     68   2531 $VERSION = '1.017';
30             }
31              
32             ######################################################################
33              
34 10     10   1588 use overload '""' => sub { $_[0]->sse },
35 68     68   361 ;
  68         149  
  68         513  
36              
37             =head1 METHODS
38              
39             Beyond the methods documented below, this class inherits methods from the
40             L<RDF::Trine::Node> class.
41              
42             =over 4
43              
44             =cut
45              
46             =item C<new ( $name )>
47              
48             Returns a new Variable structure.
49              
50             =cut
51              
52             sub new {
53 4420     4420 1 10842 my $class = shift;
54 4420         6674 my $name = shift;
55 4420         16324 return bless( [ $name ], $class );
56             }
57              
58             =item C<< name >>
59              
60             Returns the name of the variable.
61              
62             =cut
63              
64             sub name {
65 9128     9128 1 14043 my $self = shift;
66 9128         28352 return $self->[0];
67             }
68              
69             =item C<< sse >>
70              
71             Returns the SSE string for this variable.
72              
73             =cut
74              
75             sub sse {
76 166     166 1 293 my $self = shift;
77 166         382 my $name = $self->name;
78 166         895 return qq(?${name});
79             }
80              
81             =item C<< as_string >>
82              
83             Returns a string representation of the node.
84              
85             =cut
86              
87             sub as_string {
88 32     32 1 56 my $self = shift;
89 32         80 return '?' . $self->name;
90             }
91              
92             =item C<< value >>
93              
94             Returns the variable name.
95              
96             =cut
97              
98             sub value {
99 0     0 1 0 my $self = shift;
100 0         0 return $self->name;
101             }
102              
103             =item C<< as_ntriples >>
104              
105             Returns the node in a string form suitable for NTriples serialization.
106              
107             =cut
108              
109             sub as_ntriples {
110 1     1 1 37 my $self = shift;
111 1         15 throw RDF::Trine::Error::UnimplementedError -text => "Variable nodes aren't allowed in NTriples";
112             }
113              
114             =item C<< type >>
115              
116             Returns the type string of this node.
117              
118             =cut
119              
120             sub type {
121 3     3 1 8 return 'VAR';
122             }
123              
124             =item C<< equal ( $node ) >>
125              
126             Returns true if the two nodes are equal, false otherwise.
127              
128             =cut
129              
130             sub equal {
131 4     4 1 8 my $self = shift;
132 4         6 my $node = shift;
133 4 100 100     40 return 0 unless (blessed($node) and $node->isa('RDF::Trine::Node'));
134 2 100       7 return 0 unless ($self->type eq $node->type);
135 1         4 return ($self->name eq $node->name);
136             }
137              
138             # called to compare two nodes of the same type
139             sub _compare {
140 0     0     my $a = shift;
141 0           my $b = shift;
142 0           return ($a->name cmp $b->name);
143             }
144              
145             1;
146              
147             __END__
148              
149             =back
150              
151             =head1 BUGS
152              
153             Please report any bugs or feature requests to through the GitHub web interface
154             at L<https://github.com/kasei/perlrdf/issues>.
155              
156             =head1 AUTHOR
157              
158             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
159              
160             =head1 COPYRIGHT
161              
162             Copyright (c) 2006-2012 Gregory Todd Williams. This
163             program is free software; you can redistribute it and/or modify it under
164             the same terms as Perl itself.
165              
166             =cut