RDF/Trine/Error.pm

filter: Statementstmt 42.0% 53 / 126 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 18 / 21 Podpod n/a totaltotal 43.8% 71 / 162 CC 8 SCAR 20.4
CC
8
Cov
38%
explain
30.0
explain
12.0
_get_line
6.0
CRAP 7.7
« RDF/Trine/Statement/Quad.pm ↑ Summary RDF/Trine/Statement.pm »
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.019
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 68 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 68 ▶use base qw(Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 ######################################################################
38  
39 68 our ($VERSION);
40 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 $VERSION = '1.019';
42 }
43  
44 ######################################################################
45  
46 package RDF::Trine::Error::CompilationError;
47  
48 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 package RDF::Trine::Error::QuerySyntaxError;
51  
52 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 package RDF::Trine::Error::MethodInvocationError;
55  
56 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 package RDF::Trine::Error::SerializationError;
59  
60 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 package RDF::Trine::Error::DatabaseError;
63  
64 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 package RDF::Trine::Error::ParserError;
67  
68 68 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 package RDF::Trine::Error::ParserError::Explainable;
71  
72 68 ▶use base qw(RDF::Trine::Error::ParserError);
Subroutine BEGIN: called CC=1 SCAR=0.0
73 68 ▶use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 68 our $ANSI;
76 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
77 68 $ANSI = can_load( modules => { 'Term::ANSIColor' => undef } );
78 }
79  
80 0 ▶sub _get_line {
Subroutine _get_line: not called CC=2 SCAR=17.9
81 0 my $self = shift;
82 0 my $fh = shift;
83 0 my $line = shift;
84 0 my $buffer;
85 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
--$line and do { do { $buffer = $fh->getline } } 0 0 0
86 0 $buffer = $fh->getline;
87 } while (--$line);
88 0 return $buffer;
89 }
90  
91 package RDF::Trine::Error::ParserError::Tokenized;
92  
93 68 ▶use base qw(RDF::Trine::Error::ParserError::Explainable);
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 0 ▶sub explain {
Subroutine explain: not called CC=5 SCAR=34.0
96 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 ▶ if ($t->line == $t->start_line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->line == $t->start_line) { } 0 0 0
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 ▶ if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RDF::Trine::Error::ParserError::Explainable::ANSI) { } 0 0 0
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 ▶ if ($len > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 1) 0 0 0
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 ▶ if ($len > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 1) 0 0 0
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 ▶use base qw(RDF::Trine::Error::ParserError::Explainable);
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 0 ▶sub explain {
Subroutine explain: not called CC=3 SCAR=24.8
152 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 ▶ my $buffer = $self->_get_line( $fh, $line ) || '';
Condition0%0/2
$self->_get_line($fh, $line) || ''
l!l
00
MC/DC0%0/1
$self->_get_line($fh, $line) || ''
$self->_get_line($fh, $line)
Truth table0%0/2
A
A= $self->_get_line($fh, $line)
Aresult
11
00
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 ▶ if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RDF::Trine::Error::ParserError::Explainable::ANSI) { } 0 0 0
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 ▶use base qw(RDF::Trine::Error);
Subroutine BEGIN: called CC=1 SCAR=0.0
188  
189 68 1;
190  
191 __END__
« RDF/Trine/Statement/Quad.pm ↑ Summary RDF/Trine/Statement.pm »