1package Net::RNDC::Exception;
2{
3  $Net::RNDC::Exception::VERSION = '0.003';
4}
5
6use strict;
7use warnings;
8
9sub new {
10	my ($class, $error, $level) = @_;
11
12	$level ||= 1;
13
14	my (undef, $file, $line) = caller($level);
15
16	return bless {
17		error => $error,
18		file  => $file,
19		line  => $line,
20	}, $class;
21}
22
23sub error {
24	my ($self) = @_;
25
26	return "'$self->{error}' at '$self->{file}' line '$self->{line}'";
27}
28
291;
30__END__
31
32=head1 NAME
33
34Net::RNDC::Exception - Internal exception class
35
36=head1 VERSION
37
38version 0.003
39
40=head1 SYNOPSIS
41
42For use within Net::RNDC* only.
43
44To throw an error:
45
46  die Net::RNDC::Exception->new("some error");
47
48Typically used with L<Try::Tiny>:
49
50  try {
51    something_that_dies_like_above();
52  } catch {
53    my $err = $_;
54    if (UNIVERSAL::isa($err, 'Net::RNDC::Exception')) {
55      warn "Error: " . $err->error . "\n";
56    }
57  };
58
59=head1 DESCRIPTION
60
61This package is used to pass exceptions around internally so that a simple error
62interface can be exposed by the API and any actual exceptions are real problems
63with usage/bugs.
64
65=head2 Constructor
66
67=head3 new
68
69  Net::RNDC::Exception->new($error);
70
71Constructs a new exception with the given B<$error> and attached file/line
72number information to it.
73
74Required Arguments:
75
76=over 4
77
78=item *
79
80B<$error> - A string describing the error.
81
82=back
83
84=head2 Methods
85
86=head3 Error
87
88  my $error = $exception->error;
89
90Returns a string containing the error from object construction, along with a
91file and line identifier.
92
93=head1 AUTHOR
94
95Matthew Horsfall (alh) <WolfSage@gmail.com>
96
97=head1 LICENSE
98
99You may distribute this code under the same terms as Perl itself.
100
101=cut
102