/usr/share/perl5/RDF/Trine/Statement/Quad.pm is in librdf-trine-perl 1.014-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | # RDF::Trine::Statement::Quad
# -----------------------------------------------------------------------------
=head1 NAME
RDF::Trine::Statement::Quad - Class for quads and quad patterns
=head1 VERSION
This document describes RDF::Trine::Statement::Quad version 1.014
=cut
package RDF::Trine::Statement::Quad;
use strict;
use warnings;
no warnings 'redefine';
use base qw(RDF::Trine::Statement);
use Scalar::Util qw(blessed);
use Carp qw(croak);
######################################################################
our ($VERSION);
BEGIN {
$VERSION = '1.014';
}
######################################################################
=head1 METHODS
Beyond the methods documented below, this class inherits methods from the
L<RDF::Trine::Statement> class.
=over 4
=cut
=item C<new ( $s, $p, $o, $c )>
Returns a new Quad structure.
=cut
sub new {
my $class = shift;
my @nodes = @_;
unless (scalar(@nodes) == 4) {
throw RDF::Trine::Error::MethodInvocationError -text => "Quad constructor must have four node arguments";
}
my @names = qw(subject predicate object context);
foreach my $i (0 .. 3) {
unless (defined($nodes[ $i ])) {
$nodes[ $i ] = RDF::Trine::Node::Variable->new($names[ $i ]);
}
}
return bless( [ @nodes ], $class );
}
=item C<< nodes >>
Returns the subject, predicate and object of the triple pattern.
=cut
sub nodes {
my $self = shift;
return @$self;
}
=item C<< node_names >>
Returns the method names for accessing the nodes of this statement.
=cut
sub node_names {
return qw(subject predicate object context);
}
=item C<< graph >>
=item C<< context >>
Returns the graph node of the quad pattern.
=cut
sub context {
my $self = shift;
if (@_) {
$self->[3] = shift;
}
return $self->[3];
}
*graph = \&context;
=item C<< sse >>
Returns the SSE string for this algebra expression.
=cut
sub sse {
my $self = shift;
my $context = shift;
my @nodes = $self->nodes;
my @sse = map { $_->sse( $context ) } (@nodes);
return sprintf( '(quad %s %s %s %s)', @sse );
}
=item C<< type >>
Returns the type of this algebra expression.
=cut
sub type {
return 'QUAD';
}
=item C<< clone >>
=cut
sub clone {
my $self = shift;
my $class = ref($self);
return $class->new( $self->nodes );
}
=item C<< from_redland ( $statement, $name ) >>
Given a RDF::Redland::Statement object and a graph name, returns a perl-native
RDF::Trine::Statement::Quad object.
=cut
sub from_redland {
my $self = shift;
my $rstmt = shift;
my $graph = shift;
my $rs = $rstmt->subject;
my $rp = $rstmt->predicate;
my $ro = $rstmt->object;
my $cast = sub {
my $node = shift;
my $type = $node->type;
if ($type == $RDF::Redland::Node::Type_Resource) {
return RDF::Trine::Node::Resource->new( $node->uri->as_string );
} elsif ($type == $RDF::Redland::Node::Type_Blank) {
return RDF::Trine::Node::Blank->new( $node->blank_identifier );
} elsif ($type == $RDF::Redland::Node::Type_Literal) {
my $lang = $node->literal_value_language;
my $dturi = $node->literal_datatype;
my $dt = ($dturi)
? $dturi->as_string
: undef;
return RDF::Trine::Node::Literal->new( $node->literal_value, $lang, $dt );
} else {
croak 'Unknown node type in statement conversion';
}
};
my @nodes;
foreach my $n ($rs, $rp, $ro) {
push(@nodes, $cast->( $n ));
}
my $st = $self->new( @nodes, $graph );
return $st;
}
1;
__END__
=back
=head1 BUGS
Please report any bugs or feature requests to through the GitHub web interface
at L<https://github.com/kasei/perlrdf/issues>.
=head1 AUTHOR
Gregory Todd Williams C<< <gwilliams@cpan.org> >>
=head1 COPYRIGHT
Copyright (c) 2006-2012 Gregory Todd Williams. This
program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
|