File Coverage

blib/lib/BZ/Client/Exception.pm
Criterion Covered Total %
statement 6 18 33.3
branch n/a
condition 0 3 0.0
subroutine 2 7 28.5
pod 5 5 100.0
total 13 33 39.3


line stmt bran cond sub pod time code
1             #!/bin/false
2             # PODNAME: BZ::Client::Exception
3             # ABSTRACT: Exception class thrown by BZ::Client in case of errors.
4              
5 1     1   3 use strict;
  1         1  
  1         27  
6 1     1   3 use warnings 'all';
  1         2  
  1         153  
7              
8             package BZ::Client::Exception;
9             $BZ::Client::Exception::VERSION = '4.4001_002'; # TRIAL
10              
11             $BZ::Client::Exception::VERSION = '4.4001002';
12             sub throw {
13 0     0 1   my $class = shift;
14 0           die $class->new(@_)
15             }
16              
17             sub new {
18 0     0 1   my $class = shift;
19 0           my $self = { @_ };
20 0   0       bless($self, ref($class) || $class);
21 0           return $self
22             }
23              
24             sub message {
25 0     0 1   my $self = shift;
26 0           return $self->{'message'}
27             }
28              
29             sub xmlrpc_code {
30 0     0 1   my $self = shift;
31 0           return $self->{'xmlrpc_code'}
32             }
33              
34             sub http_code {
35 0     0 1   my $self = shift;
36 0           return $self->{'http_code'}
37             }
38              
39             1;
40              
41             __END__
42              
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             BZ::Client::Exception - Exception class thrown by BZ::Client in case of errors.
50              
51             =head1 VERSION
52              
53             version 4.4001_002
54              
55             =head1 SYNOPSIS
56              
57             BZ::Client does not return error codes or do similar stuff.
58             Instead, it throws instances of BZ::Client::Exception.
59              
60             my $exception = BZ::Client::Exception->new( message => $message,
61             http_code => $httpCode,
62             xmlrpc_code => $xmlrpcCode );
63              
64             BZ::Client::Exception->throw( message => $message,
65             http_code => $httpCode,
66             xmlrpc_code => $xmlrpcCode );
67              
68             =head1 METHODS
69              
70             =head2 new
71              
72             Creates the exception object
73              
74             =head2 throw
75              
76             Creates the exception object then dies, so make sure you catch it!
77              
78             =head2 message
79              
80             Returns the error message text
81              
82             =head2 xmlrpc_code
83              
84             Returns the error code from XMLRPC
85              
86             =head2 http_code
87              
88             Returns the http code (200, 404, etc)
89              
90             =head1 EXAMPLE
91              
92             Here are two examples. The first uses Perl's inbuilt eval() function, the
93             second uses the Try::Tiny module. Further alternatives exist and may be
94             perfectly good options if they suit you.
95              
96             =head2 eval
97              
98             use BZ::Client;
99             use BZ::Client::Bug::Attachment;
100             use v5.10;
101              
102             my $client = BZ::Client->new( %etc );
103              
104             eval {
105             my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
106             };
107              
108             if ($@) {
109             say 'An Error Occured';
110             say 'Message: ', $@->message();
111             say 'HTTP Code: ', $@->http_code() if $@->http_code();
112             say 'XMLrpc Code: ', $@->xmlrpc_code() if $@->xmlrpc_code();
113             };
114              
115             =head2 Try::Tiny
116              
117             use BZ::Client;
118             use BZ::Client::Bug::Attachment;
119             use Try::Tiny;
120             use v5.10;
121              
122             my $client = BZ::Client->new( %etc );
123              
124             try {
125             my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
126             }
127              
128             catch {
129             say 'An Error Occured';
130             say 'Message: ', $_->message();
131             say 'HTTP Code: ', $_->http_code() if $_->http_code();
132             say 'XMLrpc Code: ', $_->xmlrpc_code() if $_->xmlrpc_code();
133             };
134              
135             =head1 SEE ALSO
136              
137             L<BZ::Client>
138              
139             =head1 AUTHORS
140              
141             =over 4
142              
143             =item *
144              
145             Dean Hamstead <dean@bytefoundry.com.au>
146              
147             =item *
148              
149             Jochen Wiedmann <jochen.wiedmann@gmail.com>
150              
151             =back
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is copyright (c) 2017 by Dean Hamstad.
156              
157             This is free software; you can redistribute it and/or modify it under
158             the same terms as the Perl 5 programming language system itself.
159              
160             =cut