File Coverage

blib/lib/RDF/SIO/Utils/Trine.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             package RDF::SIO::Utils::Trine;
2             {
3             $RDF::SIO::Utils::Trine::VERSION = '0.003';
4             }
5             BEGIN {
6 1     1   16 $RDF::SIO::Utils::Trine::VERSION = '0.003';
7             }
8 1     1   3 use strict;
  1         2  
  1         21  
9 1     1   4 use Carp;
  1         1  
  1         39  
10 1     1   149978 use RDF::Trine;
  0            
  0            
11             use RDF::Trine::Node::Resource;
12             use RDF::Trine::Node::Literal;
13             use RDF::Trine::Statement;
14             use RDF::Trine::Statement::Quad;
15              
16              
17             use vars qw($AUTOLOAD @ISA);
18              
19             use vars qw /$VERSION/;
20              
21              
22             =head1 NAME
23              
24             RDF::SIO::Utils::Trine - Things that make RDF::Trine work the way I think it should
25              
26             =head1 SYNOPSIS
27              
28             use RDF::SIO::Utils::Trine;
29             my $t = $RDF::SIO::Utils::Trine->new();
30             my $node = $t->iri("http://example.com/nodeid");
31            
32             # or you can get the one auto-generated by RDF::SIO::Utils
33            
34             use RDF::SIO::Utils;
35             my $SIO = RDF::SIO::Utils->new();
36            
37             # auto created RDF::SIO::Utils::Trine is there
38             my $m = $SIO->Trine->temporary_model();
39             my $node2 = $SIO->Trine->iri("http://example.com/nodeid");
40              
41              
42             =cut
43              
44             =head1 DESCRIPTION
45              
46             Typing in $node = RDF::Trine::iri("http://blah.com/") every time
47             was driving me insane. Wanted it to be a bit more... lazy...
48              
49             =cut
50              
51             =head1 AUTHORS
52              
53             Mark Wilkinson (markw at illuminae dot com)
54              
55              
56             =cut
57              
58             =head1 METHODS
59              
60              
61             =head2 new
62              
63             Usage : my $trine = SIO::Utils::Trine->new;
64             Function :
65             Returns :
66             Args :
67              
68              
69             =cut
70              
71              
72             =head2 temporary_model
73              
74             Usage : my $Model = $trine->temporary_model();
75             Function :
76             Returns :
77             Args :
78              
79              
80              
81             =head2 iri
82              
83             Usage : my $Node = $trine->iri($uri);
84             Function :
85             Returns :
86             Args :
87              
88              
89             =cut
90              
91              
92             =head2 blank
93              
94             Usage : my $bNode = $trine->blank($id);
95             Function :
96             Returns :
97             Args :
98              
99              
100             =cut
101              
102              
103             =head2 literal
104              
105             Usage : my $lit = $trine->literal("val", "en", "string");
106             Function :
107             Returns :
108             Args :
109              
110              
111             =cut
112              
113              
114             =head2 statement
115              
116             Usage : my $stm = $trine->statement($s, $p, $o);
117             Function :
118             Returns :
119             Args : $s, $p, $o as Trine Nodes or literals
120              
121              
122             =cut
123              
124              
125             {
126              
127             # Encapsulated:
128             # DATA
129             #___________________________________________________________
130             #ATTRIBUTES
131             my %_attr_data = # DEFAULT ACCESSIBILITY
132             (
133             );
134              
135             #_____________________________________________________________
136             # METHODS, to operate on encapsulated class data
137             # Is a specified object attribute accessible in a given mode
138             sub _accessible {
139             my ( $self, $attr, $mode ) = @_;
140             $_attr_data{$attr}[1] =~ /$mode/;
141             }
142              
143             # Classwide default value for a specified object attribute
144             sub _default_for {
145             my ( $self, $attr ) = @_;
146             $_attr_data{$attr}[0];
147             }
148              
149             # List of names of all specified object attributes
150             sub _standard_keys {
151             keys %_attr_data;
152             }
153              
154             }
155              
156             sub new {
157             my ( $caller, %args ) = @_;
158             my $caller_is_obj = ref( $caller );
159             return $caller if $caller_is_obj;
160             my $class = $caller_is_obj || $caller;
161             my $proxy;
162             my $self = bless {}, $class;
163             foreach my $attrname ( $self->_standard_keys ) {
164             if ( exists $args{$attrname} ) {
165             $self->{$attrname} = $args{$attrname};
166             } elsif ( $caller_is_obj ) {
167             $self->{$attrname} = $caller->{$attrname};
168             } else {
169             $self->{$attrname} = $self->_default_for( $attrname );
170             }
171             }
172              
173             return $self;
174             }
175              
176              
177             sub temporary_model {
178             my ($self ) = @_;
179             my $model = RDF::Trine::Model->temporary_model;
180             return $model;
181             }
182              
183              
184             sub iri {
185             my ($self, $iri ) = @_;
186             my $node = RDF::Trine::iri($iri);
187             return $node;
188             }
189              
190              
191             sub blank {
192             my ($self, $id) = @_;
193             my $node = RDF::Trine::blank($id);
194             return $node;
195             }
196              
197             sub literal {
198             my ($self, $val, $lang, $dt ) = @_;
199             my $node = RDF::Trine::literal($val, $lang, $dt);
200             return $node;
201             }
202              
203             sub statement {
204             my ($self, $s, $p, $o ) = @_;
205             my $node = RDF::Trine::statement($s, $p, $o);
206             return $node;
207             }
208              
209              
210              
211             sub AUTOLOAD {
212              
213             no strict "refs";
214             my ( $self, $newval ) = @_;
215             $AUTOLOAD =~ /.*::(\w+)/;
216             my $attr = $1;
217             if ( $self->_accessible( $attr, 'write' ) ) {
218             *{$AUTOLOAD} = sub {
219             if ( defined $_[1] ) { $_[0]->{$attr} = $_[1]; }
220             return $_[0]->{$attr};
221             }; ### end of created subroutine
222             ### this is called first time only
223             if ( defined $newval ) {
224             $self->{$attr} = $newval;
225             }
226             return $self->{$attr};
227             } elsif ( $self->_accessible( $attr, 'read' ) ) {
228             *{$AUTOLOAD} = sub {
229             return $_[0]->{$attr};
230             }; ### end of created subroutine
231             return $self->{$attr};
232             }
233            
234             # Must have been a mistake then...
235             croak "No such method: $AUTOLOAD";
236             }
237             sub DESTROY { }
238             1;