File Coverage

blib/lib/Text/Parser/Error.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Text::Parser::Error 1.000;
2 43     43   414225 use strict;
  43         226  
  43         1413  
3 43     43   270 use warnings;
  43         103  
  43         1246  
4              
5             # ABSTRACT: Exceptions for Text::Parser
6              
7 43     43   2968 use Moose;
  43         2008654  
  43         305  
8 43     43   300105 use Moose::Exporter;
  43         114  
  43         248  
9             extends 'Throwable::Error';
10              
11             Moose::Exporter->setup_import_methods( as_is => ['parser_exception'], );
12              
13              
14             sub parser_exception {
15 50     50 1 305     my $str = shift;
16 50 100       149     $str = 'Unknown error from ' . caller() if not defined $str;
17 50         578     Text::Parser::Error->throw( message => $str );
18             }
19              
20             1;
21              
22             __END__
23            
24             =pod
25            
26             =encoding UTF-8
27            
28             =head1 NAME
29            
30             Text::Parser::Error - Exceptions for Text::Parser
31            
32             =head1 VERSION
33            
34             version 1.000
35            
36             =head1 DESCRIPTION
37            
38             This class replaces the older C<Text::Parser::Errors> which created hundreds of subclasses. That method seemed very counter-productive and difficult to handle for programmers. There is only one function in this class that is used inside the L<Text::Parser> package.
39            
40             Any exceptions thrown by this package will be an instance of L<Text::Parser::Error>. And C<Text::Parser::Error> is a subclass of C<Throwable::Error>. So you can write your code like this:
41            
42             use Try::Tiny;
43            
44             try {
45             my $parser = Text::Parser->new();
46             # do something
47             $parser->read();
48             } catch {
49             print $_->as_string, "\n" if $_->isa('Text::Parser::Error');
50             };
51            
52             =head1 FUNCTIONS
53            
54             =head2 parser_exception
55            
56             Accepts a single string argument and uses it as the message attribute for the exception thrown.
57            
58             parser_exception("Something bad happened") if $something_bad;
59            
60             =head1 BUGS
61            
62             Please report any bugs or feature requests on the bugtracker website
63             L<http://github.com/balajirama/Text-Parser/issues>
64            
65             When submitting a bug or request, please include a test-file or a
66             patch to an existing test-file that illustrates the bug or desired
67             feature.
68            
69             =head1 AUTHOR
70            
71             Balaji Ramasubramanian <balajiram@cpan.org>
72            
73             =head1 COPYRIGHT AND LICENSE
74            
75             This software is copyright (c) 2018-2019 by Balaji Ramasubramanian.
76            
77             This is free software; you can redistribute it and/or modify it under
78             the same terms as the Perl 5 programming language system itself.
79            
80             =cut
81