File Coverage

blib/lib/RDF/Lazy/Resource.pm
Criterion Covered Total %
statement 35 36 97.2
branch 5 6 83.3
condition 5 8 62.5
subroutine 11 12 91.6
pod 2 3 66.6
total 58 65 89.2


line stmt bran cond sub pod time code
1             package RDF::Lazy::Resource;
2 9     9   43 use strict;
  9         19  
  9         231  
3 9     9   43 use warnings;
  9         15  
  9         229  
4              
5 9     9   42 use base 'RDF::Lazy::Node';
  9         33  
  9         615  
6 9     9   45 use Scalar::Util qw(blessed);
  9         20  
  9         391  
7 9     9   91 use CGI qw(escapeHTML);
  9         17  
  9         48  
8 9     9   759 use Try::Tiny;
  9         23  
  9         639  
9              
10 9     9   43 use overload '""' => \&str;
  9         23  
  9         69  
11              
12             sub new {
13 131     131 0 230 my $class = shift;
14 131   33     326 my $graph = shift || RDF::Lazy->new;
15 131         196 my $resource = shift;
16              
17 131 100       291 return unless defined $resource;
18              
19 125 100 66     584 unless (blessed($resource) and $resource->isa('RDF::Trine::Node::Resource')) {
20 81         334 $resource = RDF::Trine::Node::Resource->new( $resource );
21 81 50       1278 return unless defined $resource;
22             }
23              
24 125         765 return bless [ $resource, $graph ], $class;
25             }
26              
27             sub str {
28 137     137 1 3141 shift->trine->uri_value;
29             }
30              
31             *uri = *str;
32              
33             *href = *RDF::Lazy::Node::esc;
34              
35             sub qname {
36 3     3 1 573 my $self = shift;
37             try {
38 3     3   166 my ($ns,$local) = $self->[0]->qname; # let Trine split
39 3   100     1369 $ns = $self->[1]->ns($ns) || return "";
40 2         10 return "$ns:$local";
41             } catch {
42 0     0     return "";
43             }
44 3         26 }
45              
46             1;
47             __END__
48              
49             =head1 NAME
50              
51             RDF::Lazy::Resource - URI reference node (aka resource) in a RDF::Lazy graph
52              
53             =head1 DESCRIPTION
54              
55             You should not directly create instances of this class.
56             See L<RDF::Lazy::Node> for general node properties.
57              
58             =head1 METHODS
59              
60             =head2 str
61              
62             Return the URI value of this node as string. Is also used for comparing nodes.
63              
64             =head2 uri
65              
66             Alias for method 'str'.
67              
68             =head2 href
69              
70             Return the HTML-escaped URI value. Alias for method 'esc'.
71              
72             =head2 qname
73              
74             Returns a qualified name (C<prefix:local>) if a mathcing namespace prefix is
75             defined. See also method L<RDF::Lazy#ns> for namespace handling.
76              
77             =cut