File: Error.pm

package info (click to toggle)
libpandoc-wrapper-perl 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 589; makefile: 5; sh: 1
file content (62 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Pandoc::Error;
use 5.014;
use warnings;

our $VERSION = '0.9.2';

use overload '""' => 'message', fallback => 1;
use Carp;

$Carp::CarpInternal{ (__PACKAGE__) }++;   # don't include package in stack trace

sub new {
    my ( $class, %fields ) = @_ % 2 ? @_ : ( shift, message => @_ );
    $fields{message} = Carp::shortmess( $fields{message} // $class );
    bless \%fields, $class;
}

sub throw {
    die ref $_[0] ? $_[0] : shift->new(@_);
}

sub message {
    $_[0]->{message};
}

1;

=head1 NAME

Pandoc::Error - Pandoc document processing error

=head1 SYNOPSIS

  use Try::Tiny;

  try {
      ...
  } catch {
      if ( blessed $_ && $_->isa('Pandoc::Error') ) {
          ...
      }
  };

=head1 METHODS

=head2 throw( [ %fields ] )

Throw an existing error or create and throw a new error. Setting field
C<message> is recommended. The message is enriched with error location.  A
stack trace can be added with L<$Carp::Verbose|Carp/$Carp::Verbose> or
L<Carp::Always>.

=head2 message

The error message. Also returned on stringification.

=head1 SEE ALSO

This class does not inherit from L<Throwable>, L<Exception::Class> or
L<Class::Exception> but may do so in a future version.

=cut