blib/lib/VM/EC2/VPC/PeeringConnection.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 76 CC 3 SCAR 11.0
CC
3
Cov
0%
refresh
6.0
current_status
6.0
primary_id
2.0
CRAP 3.0
1 package VM::EC2::VPC::PeeringConnection;
2  
3 =head1 NAME
4  
5 VM::EC2::VPC::PeeringConnection - Virtual Private Cloud Peering Connection
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 my $ec2 = VM::EC2->new(...);
12 my $pcx = $ec2->describe_vpc_peering_connections(-vpc_peering_connection_id=>'pcx-12345678');
13 my $status = $pcx->status;
14  
15 =head1 DESCRIPTION
16  
17 This object represents an Amazon EC2 VPC peering connection, and is returned by
18 VM::EC2->describe_vpc_peering_connections(), create_vpc_peering_connection(), and
19 accept_vpc_peering_connection().
20  
21 =head1 METHODS
22  
23 These object methods are supported:
24  
25 vpcPeeringConnectionId -- The ID of the VPC peering connection
26 requesterVpcInfo -- Information about the requester VPC
27 accepterVpcInfo -- Information about the accepter VPC
28 status -- The status of the VPC peering connection
29 expirationTime -- The time that an unaccepted VPC peering
30 connection will expire
31 tagSet -- Tags assigned to the resource.
32  
33 The following convenience methods are provided:
34  
35 accept -- Accepts the peering connection request.
36 NOTE: must be in the 'pending-acceptance'
37 state to be successful
38  
39 reject -- Rejects the peering connection request.
40 NOTE: must be in the 'pending-acceptance'
41 state to be successful
42  
43 refresh -- Refreshes the object
44  
45 current_status -- Refreshes the object and returns the
46 status. Useful for checking status
47 after calling reject() or accept()
48  
49 The object also supports the tags() method described in
50 L<VM::EC2::Generic>:
51  
52 =head1 STRING OVERLOADING
53  
54 When used in a string context, this object will interpolate the
55 vpcPeeringConnectionId
56  
57 =head1 SEE ALSO
58  
59 L<VM::EC2>
60 L<VM::EC2::Generic>
61 L<VM::EC2::Tag>
62 L<VM::EC2::VPC>
63  
64 =head1 AUTHOR
65  
66 Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt>.
67  
68 Copyright (c) 2014 Loyalty Methods, Inc.
69  
70 This package and its accompanying libraries is free software; you can
71 redistribute it and/or modify it under the terms of the GPL (either
72 version 1, or at your option, any later version) or the Artistic
73 License 2.0. Refer to LICENSE for the full license text. In addition,
74 please see DISCLAIMER.txt for disclaimers of warranty.
75  
76 =cut
77  
78 use strict;
79 use base 'VM::EC2::Generic';
80 use VM::EC2::VPC::PeeringConnection::VpcInfo;
81 use VM::EC2::VPC::PeeringConnection::StateReason;
82 use Carp 'croak';
83  
84 sub primary_id { shift->vpcPeeringConnectionId }
85  
86 sub valid_fields {
87 my $self = shift;
88 return qw(vpcPeeringConnectionId requesterVpcInfo accepterVpcInfo
89 status expirationTime tagSet);
90 }
91  
92 sub requesterVpcInfo {
93 my $self = shift;
94 my $info = $self->SUPER::requesterVpcInfo or return;
95 return VM::EC2::VPC::PeeringConnection::VpcInfo->new($info,$self->aws);
96 }
97  
98 sub accepterVpcInfo {
99 my $self = shift;
100 my $info = $self->SUPER::accepterVpcInfo or return;
101 return VM::EC2::VPC::PeeringConnection::VpcInfo->new($info,$self->aws);
102 }
103  
104 sub status {
105 my $self = shift;
106 my $status = $self->SUPER::status or return;
107 return VM::EC2::VPC::PeeringConnection::StateReason->new($status,$self->aws);
108 }
109  
110 sub accept {
111 my $self = shift;
112 return $self->aws->accept_vpc_peering_connection(-vpc_peering_connection_id => $self->vpcPeeringConnectionId);
113 }
114  
115 sub reject {
116 my $self = shift;
117 return $self->aws->reject_vpc_peering_connection(-vpc_peering_connection_id => $self->vpcPeeringConnectionId);
118 }
119  
120 sub refresh {
121 my $self = shift;
122 local $self->aws->{raise_error} = 1;
123 my ($pcx) = $self->aws->describe_vpc_peering_connections(-vpc_peering_connection_id => $self->vpcPeeringConnectionId);
124 %$self = %$pcx if $pcx;
125 return defined $pcx;
126 }
127  
128 sub current_status {
129 my $self = shift;
130 my $retry = 0;
131 until ($self->refresh) {
132 if (++$retry > 10) {
133 croak "invalid peering connection: ",$self->vpcPeeringConnectionId;
134 }
135 sleep 2;
136 }
137 return $self->status;
138 }
139  
140 1;