File Coverage

blib/lib/RDF/Trine/Error.pm
Criterion Covered Total %
statement 50 123 40.6
branch 0 10 0.0
condition 0 2 0.0
subroutine 18 21 85.7
pod n/a
total 68 156 43.5


line stmt bran cond sub pod time code
1             # RDF::Trine::Error
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Trine::Error - Error classes for RDF::Trine
7              
8             =head1 VERSION
9              
10             This document describes RDF::Trine::Error version 1.017
11              
12             =head1 SYNOPSIS
13              
14             use RDF::Trine::Error qw(:try);
15              
16             =head1 DESCRIPTION
17              
18             RDF::Trine::Error provides a class hierarchy of errors that other RDF::Trine
19             classes may throw using the L<Error|Error> API. See L<Error> for more
20             information.
21              
22             =head1 REQUIRES
23              
24             L<Error|Error>
25              
26             =cut
27              
28             package RDF::Trine::Error;
29              
30 68     68   387 use strict;
  68         126  
  68         1518  
31 68     68   287 use warnings;
  68         120  
  68         1379  
32 68     68   300 no warnings 'redefine';
  68         130  
  68         1786  
33 68     68   335 use Carp qw(carp croak confess);
  68         128  
  68         3064  
34              
35 68     68   358 use base qw(Error);
  68         138  
  68         28964  
36              
37             ######################################################################
38              
39             our ($VERSION);
40             BEGIN {
41 68     68   196394 $VERSION = '1.017';
42             }
43              
44             ######################################################################
45              
46             package RDF::Trine::Error::CompilationError;
47              
48 68     68   465 use base qw(RDF::Trine::Error);
  68         156  
  68         4469  
49              
50             package RDF::Trine::Error::QuerySyntaxError;
51              
52 68     68   399 use base qw(RDF::Trine::Error);
  68         140  
  68         3806  
53              
54             package RDF::Trine::Error::MethodInvocationError;
55              
56 68     68   381 use base qw(RDF::Trine::Error);
  68         137  
  68         3649  
57              
58             package RDF::Trine::Error::SerializationError;
59              
60 68     68   377 use base qw(RDF::Trine::Error);
  68         140  
  68         3650  
61              
62             package RDF::Trine::Error::DatabaseError;
63              
64 68     68   362 use base qw(RDF::Trine::Error);
  68         138  
  68         3739  
65              
66             package RDF::Trine::Error::ParserError;
67              
68 68     68   353 use base qw(RDF::Trine::Error);
  68         182  
  68         3804  
69              
70             package RDF::Trine::Error::ParserError::Explainable;
71              
72 68     68   370 use base qw(RDF::Trine::Error::ParserError);
  68         142  
  68         18343  
73 68     68   2540 use Module::Load::Conditional qw[can_load];
  68         87944  
  68         5192  
74              
75             our $ANSI;
76             BEGIN {
77 68     68   546 $ANSI = can_load( modules => { 'Term::ANSIColor' => undef } );
78             }
79              
80             sub _get_line {
81 0     0     my $self = shift;
82 0           my $fh = shift;
83 0           my $line = shift;
84 0           my $buffer;
85 0           do {
86 0           $buffer = $fh->getline;
87             } while (--$line);
88 0           return $buffer;
89             }
90              
91             package RDF::Trine::Error::ParserError::Tokenized;
92              
93 68     68   1402643 use base qw(RDF::Trine::Error::ParserError::Explainable);
  68         170  
  68         45038  
94              
95             sub explain {
96 0     0     my $self = shift;
97 0           my $fh = shift;
98 0           seek($fh, 0, 0);
99 0           my $text = $self->text;
100 0           my $t = $self->object;
101 0           my $line = $t->start_line;
102 0           my $col = $t->start_column;
103 0           my $buffer = $self->_get_line( $fh, $line );
104 0           my $maxlen = length($buffer) - $col;
105 0           my $len = 1;
106 0 0         if ($t->line == $t->start_line) {
107 0           $len = ($t->column - $t->start_column);
108             } else {
109 0           $len = $maxlen;
110             }
111            
112 0           my $tabs = ($buffer =~ tr/\t//);
113 0           $buffer =~ s/\t/ /g;
114 0           $col += 3 * $tabs;
115            
116 0           chomp($text);
117            
118 0 0         if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
119 0           print STDERR Term::ANSIColor::color('red');
120 0           print STDERR "$text:\n";
121 0           print STDERR Term::ANSIColor::color('reset');
122 0           print STDERR substr($buffer, 0, $col-1);
123 0           print STDERR Term::ANSIColor::color('red');
124 0           print STDERR substr($buffer, $col-1, $len);
125 0           print STDERR Term::ANSIColor::color('reset');
126 0           print STDERR substr($buffer, $col+$len-1);
127 0           print STDERR " " x ($col-1);
128 0           print STDERR Term::ANSIColor::color('blue');
129 0           print STDERR "^";
130 0 0         if ($len > 1) {
131 0           print STDERR ("~" x ($len-1));
132             }
133 0           print STDERR "\n";
134 0           print STDERR Term::ANSIColor::color('reset');
135             } else {
136 0           print STDERR "$text:\n";
137 0           print STDERR $buffer;
138 0           print STDERR " " x ($col-1);
139 0           print STDERR "^";
140 0 0         if ($len > 1) {
141 0           print STDERR ("~" x ($len-1));
142             }
143 0           print STDERR "\n";
144             }
145             }
146              
147             package RDF::Trine::Error::ParserError::Positioned;
148              
149 68     68   542 use base qw(RDF::Trine::Error::ParserError::Explainable);
  68         170  
  68         29567  
150              
151             sub explain {
152 0     0     my $self = shift;
153 0           my $fh = shift;
154 0           seek($fh, 0, 0);
155 0           my $text = $self->text;
156 0           my $pos = $self->value;
157 0           my ($line, $col) = @$pos;
158 0   0       my $buffer = $self->_get_line( $fh, $line ) || '';
159            
160 0           my $tabs = ($buffer =~ tr/\t//);
161 0           $buffer =~ s/\t/ /g;
162 0           $col += 3 * $tabs;
163            
164 0           chomp($text);
165            
166 0 0         if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
167 0           print STDERR Term::ANSIColor::color('red');
168 0           print STDERR "$text:\n";
169 0           print STDERR Term::ANSIColor::color('reset');
170 0           print STDERR $buffer;
171 0           print STDERR Term::ANSIColor::color('red');
172 0           print STDERR " " x ($col-1);
173 0           print STDERR "^";
174 0           print STDERR Term::ANSIColor::color('reset');
175 0           print STDERR "\n";
176             } else {
177 0           print STDERR "$text:\n";
178 0           print STDERR $buffer;
179 0           print STDERR " " x ($col-1);
180 0           print STDERR "^";
181 0           print STDERR "\n";
182             }
183             }
184              
185             package RDF::Trine::Error::UnimplementedError;
186              
187 68     68   610 use base qw(RDF::Trine::Error);
  68         166  
  68         4392  
188              
189             1;
190              
191             __END__
192              
193             =head1 BUGS
194              
195             Please report any bugs or feature requests to through the GitHub web interface
196             at L<https://github.com/kasei/perlrdf/issues>.
197              
198             =head1 AUTHOR
199              
200             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
201              
202             =head1 COPYRIGHT
203              
204             Copyright (c) 2006-2012 Gregory Todd Williams. This
205             program is free software; you can redistribute it and/or modify it under
206             the same terms as Perl itself.
207              
208             =cut