File Coverage

blib/lib/Pandoc/Error.pm
Criterion Covered Total %
statement 16 16 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 2 3 66.6
total 29 33 87.8


line stmt bran cond sub pod time code
1             package Pandoc::Error;
2 11     11   189 use 5.014;
  11         41  
3 11     11   55 use warnings;
  11         26  
  11         576  
4              
5             our $VERSION = '0.9.0';
6              
7 11     11   67 use overload '""' => 'message', fallback => 1;
  11         20  
  11         64  
8 11     11   961 use Carp;
  11         36  
  11         2463  
9              
10             $Carp::CarpInternal{ (__PACKAGE__) }++; # don't include package in stack trace
11              
12             sub new {
13 17 100   17 0 120 my ( $class, %fields ) = @_ % 2 ? @_ : ( shift, message => @_ );
14 17   33     643 $fields{message} = Carp::shortmess( $fields{message} // $class );
15 17         6054 bless \%fields, $class;
16             }
17              
18             sub throw {
19 17 50   17 1 75 die ref $_[0] ? $_[0] : shift->new(@_);
20             }
21              
22             sub message {
23 9     9 1 300 $_[0]->{message};
24             }
25              
26             1;
27              
28             =head1 NAME
29              
30             Pandoc::Error - Pandoc document processing error
31              
32             =head1 SYNOPSIS
33              
34             use Try::Tiny;
35              
36             try {
37             ...
38             } catch {
39             if ( blessed $_ && $_->isa('Pandoc::Error') ) {
40             ...
41             }
42             };
43              
44             =head1 METHODS
45              
46             =head2 throw( [ %fields ] )
47              
48             Throw an existing error or create and throw a new error. Setting field
49             C is recommended. The message is enriched with error location. A
50             stack trace can be added with L<$Carp::Verbose|Carp/$Carp::Verbose> or
51             L.
52              
53             =head2 message
54              
55             The error message. Also returned on stringification.
56              
57             =head1 SEE ALSO
58              
59             This class does not inherit from L, L or
60             L but may do so in a future version.
61              
62             =cut