/[suikacvs]/messaging/manakai/lib/Message/Util/Error/TextParser.pm
Suika

Contents of /messaging/manakai/lib/Message/Util/Error/TextParser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Fri Oct 31 08:39:50 2003 UTC (22 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +4 -1 lines
Some fix to avoid warnings

1 wakaba 1.1
2     =head1 NAME
3    
4     Message::Util::Error::TextParser --- manakai: Common error handler wrapper for formatted-text parser
5    
6     =head1 DESCRIPTION
7    
8     This module provides common error handler (error reporting wrapper
9     module) for formatted-text parser. With this module, flexible error
10     reporting method can be easily implemented. In addition to the base
11     module of Message::Util::Error, this module implements line/position
12     counting method so that error occured position in the parsed plain-text
13     based data can be reported.
14    
15     This module is part of manakai.
16    
17     =cut
18    
19     package Message::Util::Error::TextParser;
20     use base Message::Util::Error;
21     use strict;
22     our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
23    
24     =head1 METHODS
25    
26     =over 4
27    
28     =item $err = Message::Util::Error::TextParser->new ({error definitions})
29    
30     Constructs new error reporting object. Hash reference to error definition list must be specified as an argument.
31    
32     =cut
33    
34     # Inherited
35    
36     =item $err->raise (%detail)
37    
38     Raises an error (or a warning, if defined so)
39    
40     =cut
41    
42     sub raise ($%) {
43     my ($self, %err) = @_;
44     if ($err{position}) {
45     $err{position_data} = $self->{pos}->{$err{position}};
46 wakaba 1.2 unless (defined $err{position_data}->{line}) {
47     warn qq'raise: position data "$err{position}" not initialized';
48     }
49 wakaba 1.1 $err{position_msg} = sprintf 'Line %d position %d',
50     $err{position_data}->{line}, $err{position_data}->{pos};
51     }
52     $self->SUPER::raise (%err);
53     }
54    
55     =item $self->count_position ($position_set, $text)
56    
57     Counts lines/characters and adds to current position of C<$position_set>.
58    
59     =cut
60    
61     sub count_position ($$$) {
62     my ($self, $set, $text) = @_;
63     $text =~ s/[^\x0A\x0D]*(?:\x0D\x0A?|\x0A)/$self->{pos}->{$set}->{line}++;
64     $self->{pos}->{$set}->{pos} = 0;
65     ''/ges;
66     $self->{pos}->{$set}->{pos} += length $text;
67     }
68    
69     =item $self->reset_position ($position_set)
70    
71     Resets current position of C<$position_set> to "Line 0 position 0".
72    
73     =cut
74    
75     sub reset_position ($$) {
76     my ($self, $set) = @_;
77     $self->{pos}->{$set}->{line} = 0;
78     $self->{pos}->{$set}->{pos} = 0;
79     }
80    
81     =back
82    
83     =head1 LICENSE
84    
85     Copyright 2003 Wakaba <w@suika.fam.cx>
86    
87     This program is free software; you can redistribute it and/or
88     modify it under the same terms as Perl itself.
89    
90     =cut
91    
92 wakaba 1.2 1; # $Date: 2003/08/05 07:30:14 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24