blib/lib/VM/EC2/Error.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 27 CC 1 SCAR 6.9
CC
1
Cov
0%
valid_fields
2.0
code
2.0
message
2.0
CRAP 2.0
1 package VM::EC2::Error;
2  
3 =head1 NAME
4  
5 VM::EC2::Error - Object describing an error emitted by the Amazon API
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 $ec2 = VM::EC2->new(...);
12 $instance = $ec2->describe_instance(-instance_id=>'invalid-name');
13 die $ec2->error if $ec2->is_error;
14  
15 =head1 DESCRIPTION
16  
17 This object represents an error emitted by the Amazon API. VM::EC2
18 method calls may return undef under either of two conditions: the
19 request may simply have no results that satisfy it (for example,
20 asking to describe an instance whose ID does not exist), or an error
21 occurred due to invalid parameters or communication problems.
22  
23 As described in L<VM::EC2>, the VM::EC2->is_error method returns true if
24 the last method call resulted in an error, and VM::EC2->error returns
25 the content of the error message.
26  
27 =head1 METHODS
28  
29 These object methods are supported:
30  
31 message -- the error message
32 code -- the error code
33  
34 =head1 STRING OVERLOADING
35  
36 When used in a string context, this object will interpolate the code
37 and message into a single string in the format "Message [Code]".
38  
39 =head1 SEE ALSO
40  
41 L<VM::EC2>
42 L<VM::EC2::Generic>
43  
44 =head1 AUTHOR
45  
46 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
47  
48 Copyright (c) 2011 Ontario Institute for Cancer Research
49  
50 This package and its accompanying libraries is free software; you can
51 redistribute it and/or modify it under the terms of the GPL (either
52 version 1, or at your option, any later version) or the Artistic
53 License 2.0. Refer to LICENSE for the full license text. In addition,
54 please see DISCLAIMER.txt for disclaimers of warranty.
55  
56 =cut
57  
58 use strict;
59 use base 'VM::EC2::Generic';
60  
61 use overload
62 '""' => sub {
63 my $self = shift;
64 my $msg = $self->Message;
65 $msg =~ s/\.$//;
66 my $code = $self->Code;
67 return "[$code] $msg";},
68 fallback => 1;
69  
70 sub valid_fields {
71 my $self = shift;
72 return qw(Code Message);
73 }
74  
75 # because the darn Error XML doesn't adhere
76 # to the conventions elsewhere, in which
77 # the initial letter of the tag is lowercase
78 sub code {shift->payload->{Code}}
79 sub message {shift->payload->{Message}}
80  
81 1;