File Coverage

blib/lib/RDF/Query/VariableBindings.pm
Criterion Covered Total %
statement 34 48 70.8
branch 3 4 75.0
condition 4 5 80.0
subroutine 10 12 83.3
pod 4 4 100.0
total 55 73 75.3


line stmt bran cond sub pod time code
1             # RDF::Query::VariableBindings
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::VariableBindings - Variable bindings
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::VariableBindings version 2.918.
11              
12             =head1 METHODS
13              
14             Beyond the methods documented below, this class inherits methods from the
15             L<RDF::Trine::VariableBindings> class.
16              
17             =over 4
18              
19             =cut
20              
21             package RDF::Query::VariableBindings;
22              
23 35     35   125 use strict;
  35         43  
  35         772  
24 35     35   114 use warnings;
  35         41  
  35         738  
25 35     35   114 use base qw(RDF::Trine::VariableBindings);
  35         43  
  35         3425  
26 535     535   3049 use overload '""' => sub { $_[0]->as_string },
27 35     35   178 'bool' => sub { return 1 };
  35     781   44  
  35         423  
  781         3314  
28              
29 35     35   2515 use Scalar::Util qw(blessed refaddr);
  35         50  
  35         2013  
30              
31             ######################################################################
32              
33             our ($VERSION);
34             BEGIN {
35 35     35   10601 $VERSION = '2.918';
36             }
37              
38             ######################################################################
39              
40             =item C<< new ( \%bindings ) >>
41              
42             =cut
43              
44             sub new {
45 799     799 1 6741 my $class = shift;
46 799   50     1553 my $bindings = shift || {};
47 799         24608 my $data = { %$bindings };
48 799         1740 foreach my $k (keys %$data) {
49 1594         8814 my $node = $data->{$k};
50 1594 100 100     8359 if (ref($node) and not($node->isa('RDF::Query::Node'))) {
51 756         2469 $data->{$k} = RDF::Query::Node->from_trine( $node );
52             }
53             }
54            
55 799         8353 my $self = $class->SUPER::new( $data );
56 799         6203 return $self;
57             }
58              
59             =item C<< sse ( \%context, $indent ) >>
60              
61             =cut
62              
63             sub sse {
64 7     7 1 11 my $self = shift;
65 7         11 my $context = shift;
66 7         10 my $indent = shift;
67 7         9 my $more = ' ';
68 7         24 my @keys = sort keys %$self;
69 7 50       39 return sprintf('(row %s)', CORE::join(' ', map { '[' . CORE::join(' ', '?' . $_, ($self->{$_}) ? $self->{$_}->as_string : ()) . ']' } (@keys)));
  5         116  
70             }
71              
72             =item C<< explain >>
73              
74             Returns a string serialization of the variable bindings appropriate for display
75             on the command line.
76              
77             =cut
78              
79             sub explain {
80 0     0 1   my $self = shift;
81 0           my $s = shift;
82 0           my $count = shift;
83 0           my $indent = $s x $count;
84 0           my $string = "${indent}Variable Bindings\n";
85              
86 0           my @keys = sort keys %$self;
87 0           foreach my $k (@keys) {
88 0           $string .= "${indent}${s}$k: " . $self->{$k}->as_string . "\n";
89             }
90 0           return $string;
91             }
92              
93             =item C<< as_hash >>
94              
95             Returns the variable bindings as a nested set of plain data structures (no objects).
96              
97             =cut
98              
99             sub as_hash {
100 0     0 1   my $self = shift;
101 0           my $context = shift;
102 0           my @keys = sort keys %$self;
103 0           return { type => 'bindings', bindings => { map { $_ => $self->{$_}->as_hash($context) } @keys } };
  0            
104             }
105              
106              
107             1;
108              
109             __END__
110              
111             =back
112              
113             =head1 AUTHOR
114              
115             Gregory Todd Williams <gwilliams@cpan.org>
116              
117             =cut