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