~ubuntu-branches/ubuntu/trusty/librdf-trine-perl/trusty

« back to all changes in this revision

Viewing changes to lib/RDF/Trine/Error.pm

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard, Jonas Smedegaard
  • Date: 2012-12-11 04:17:02 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20121211041702-tfqq2grzobwynjpm
Tags: 1.002-1
* New upstream release.
  Highlights:
  + Replaced old Turtle and TriG parsers with new streaming
    implementations.
  + Added RDF::Trine::Node::Literal->canonicalize method.
  + Updated RDF::Trine::Parser::Redland to construct a new parser
    object on each parse (avoiding a bug in redland).
  + Applied partial patch to 'fix interaction with
    HTML::Data::Parser'.
  + Added POD to RDF::Trine and RDF::Trine::Store::DBI.
  + Silenced undefined warnings in RDF::Trine::Parser::Turtle::Lexer.
  + Silenced warning of cartesian joins in
    RDF::Trine::Store::Hexastore.

[ Jonas Smedegaard ]
* Bump debhelper compatibility level to 8.
* Update package relations:
  + (Build-)depend on libmoose-perl and libmoosex-arrayref-perl.
  + Relax to build-depend unversioned on cdbs: Needed version
    satisfied in stable, and oldstable no longer supported.
* Update copyright file:
  + Expand Files section authored by Toby Inkster, and extend
    coverage.
  + Fix use comment and license pseudo-sections to obey silly
    restrictions of copyright format 1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
=head1 VERSION
9
9
 
10
 
This document describes RDF::Trine::Error version 1.000
 
10
This document describes RDF::Trine::Error version 1.002
11
11
 
12
12
=head1 SYNOPSIS
13
13
 
38
38
 
39
39
our ($VERSION);
40
40
BEGIN {
41
 
        $VERSION        = '1.000';
 
41
        $VERSION        = '1.002';
42
42
}
43
43
 
44
44
######################################################################
67
67
 
68
68
use base qw(RDF::Trine::Error);
69
69
 
 
70
package RDF::Trine::Error::ParserError::Explainable;
 
71
 
 
72
use base qw(RDF::Trine::Error::ParserError);
 
73
use Module::Load::Conditional qw[can_load];
 
74
 
 
75
our $ANSI;
 
76
BEGIN {
 
77
        $ANSI   = can_load( modules => { 'Term::ANSIColor' => undef } );
 
78
}
 
79
 
 
80
sub _get_line {
 
81
        my $self        = shift;
 
82
        my $fh          = shift;
 
83
        my $line        = shift;
 
84
        my $buffer;
 
85
        do {
 
86
                $buffer = $fh->getline;
 
87
        } while (--$line);
 
88
        return $buffer;
 
89
}
 
90
 
 
91
package RDF::Trine::Error::ParserError::Tokenized;
 
92
 
 
93
use base qw(RDF::Trine::Error::ParserError::Explainable);
 
94
 
 
95
sub explain {
 
96
        my $self        = shift;
 
97
        my $fh          = shift;
 
98
        seek($fh, 0, 0);
 
99
        my $text        = $self->text;
 
100
        my $t           = $self->object;
 
101
        my $line        = $t->start_line;
 
102
        my $col         = $t->start_column;
 
103
        my $buffer      = $self->_get_line( $fh, $line );
 
104
        my $maxlen      = length($buffer) - $col;
 
105
        my $len         = 1;
 
106
        if ($t->line == $t->start_line) {
 
107
                $len    = ($t->column - $t->start_column);
 
108
        } else {
 
109
                $len    = $maxlen;
 
110
        }
 
111
        
 
112
        my $tabs        = ($buffer =~ tr/\t//);
 
113
        $buffer         =~ s/\t/    /g;
 
114
        $col            += 3 * $tabs;
 
115
        
 
116
        chomp($text);
 
117
        
 
118
        if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
 
119
                print STDERR Term::ANSIColor::color('red');
 
120
                print STDERR "$text:\n";
 
121
                print STDERR Term::ANSIColor::color('reset');
 
122
                print STDERR substr($buffer, 0, $col-1);
 
123
                print STDERR Term::ANSIColor::color('red');
 
124
                print STDERR substr($buffer, $col-1, $len);
 
125
                print STDERR Term::ANSIColor::color('reset');
 
126
                print STDERR substr($buffer, $col+$len-1);
 
127
                print STDERR " " x ($col-1);
 
128
                print STDERR Term::ANSIColor::color('blue');
 
129
                print STDERR "^";
 
130
                if ($len > 1) {
 
131
                        print STDERR ("~" x ($len-1));
 
132
                }
 
133
                print STDERR "\n";
 
134
                print STDERR Term::ANSIColor::color('reset');
 
135
        } else {
 
136
                print STDERR "$text:\n";
 
137
                print STDERR $buffer;
 
138
                print STDERR " " x ($col-1);
 
139
                print STDERR "^";
 
140
                if ($len > 1) {
 
141
                        print STDERR ("~" x ($len-1));
 
142
                }
 
143
                print STDERR "\n";
 
144
        }
 
145
}
 
146
 
 
147
package RDF::Trine::Error::ParserError::Positioned;
 
148
 
 
149
use base qw(RDF::Trine::Error::ParserError::Explainable);
 
150
 
 
151
sub explain {
 
152
        my $self        = shift;
 
153
        my $fh          = shift;
 
154
        seek($fh, 0, 0);
 
155
        my $text        = $self->text;
 
156
        my $pos         = $self->value;
 
157
        my ($line, $col)        = @$pos;
 
158
        my $buffer      = $self->_get_line( $fh, $line );
 
159
        
 
160
        my $tabs        = ($buffer =~ tr/\t//);
 
161
        $buffer         =~ s/\t/    /g;
 
162
        $col            += 3 * $tabs;
 
163
        
 
164
        chomp($text);
 
165
        
 
166
        if ($RDF::Trine::Error::ParserError::Explainable::ANSI) {
 
167
                print STDERR Term::ANSIColor::color('red');
 
168
                print STDERR "$text:\n";
 
169
                print STDERR Term::ANSIColor::color('reset');
 
170
                print STDERR $buffer;
 
171
                print STDERR Term::ANSIColor::color('red');
 
172
                print STDERR " " x ($col-1);
 
173
                print STDERR "^";
 
174
                print STDERR Term::ANSIColor::color('reset');
 
175
                print STDERR "\n";
 
176
        } else {
 
177
                print STDERR "$text:\n";
 
178
                print STDERR $buffer;
 
179
                print STDERR " " x ($col-1);
 
180
                print STDERR "^";
 
181
                print STDERR "\n";
 
182
        }
 
183
}
 
184
 
70
185
package RDF::Trine::Error::UnimplementedError;
71
186
 
72
187
use base qw(RDF::Trine::Error);