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

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 35 CC 4 SCAR 23.0
CC
4
Cov
0%
permissions
20.0
valid_fields
2.0
primary_id
2.0
CRAP 10.0
1 package VM::EC2::Group;
2  
3 =head1 NAME
4  
5 VM::EC2::Group - Object describing an Amazon EC2 security group name
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 $ec2 = VM::EC2->new(...);
12 $instance = $ec2->describe_instances(-instance_id=>'i-12345');
13 my @groups = $instance->groups;
14 for my $g (@groups) {
15 my $id = $g->groupId;
16 my $name = $g->groupName;
17  
18 # get the security group details
19 my $sg = $ec2->describe_security_group($g);
20 my $permissions = $sg->ipPermissions;
21 }
22  
23 =head1 DESCRIPTION
24  
25 This object represents the name and ID of a security group. It is
26 returned by an instance's groups() method. This object does not
27 provide any of the details about the security group, but you can use
28 it in a call to VM::EC2->describe_security_group() to get details about
29 the security group's allowed ports, etc.
30  
31 =head1 METHODS
32  
33 These object methods are supported:
34  
35 groupId -- the group ID
36 groupName -- the group's name
37  
38 For convenience, the object also provides a permissions() method that
39 will return the fully detailed VM::EC2::SecurityGroup:
40  
41 $details = $group->permissions()
42  
43 See L<VM::EC2::SecurityGroup>
44  
45 =head1 STRING OVERLOADING
46  
47 When used in a string context, this object will interpolate the
48 groupId.
49  
50 =head1 SEE ALSO
51  
52 L<VM::EC2>
53 L<VM::EC2::Object>
54 L<VM::EC2::Generic>
55 L<VM::EC2::SecurityGroup>
56  
57 =head1 AUTHOR
58  
59 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
60  
61 Copyright (c) 2011 Ontario Institute for Cancer Research
62  
63 This package and its accompanying libraries is free software; you can
64 redistribute it and/or modify it under the terms of the GPL (either
65 version 1, or at your option, any later version) or the Artistic
66 License 2.0. Refer to LICENSE for the full license text. In addition,
67 please see DISCLAIMER.txt for disclaimers of warranty.
68  
69 =cut
70  
71 use strict;
72 use base 'VM::EC2::Generic';
73  
74 sub valid_fields {
75 my $self = shift;
76 return $self->SUPER::valid_fields,
77 qw(groupId groupName);
78 }
79  
80 sub primary_id { shift->groupId }
81  
82 sub groupName {
83 my $self = shift;
84 my $name = $self->SUPER::groupName;
85 $name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; # for some reason this is URI encoded!
86 $name;
87 }
88  
89 sub permissions {
90 my $self = shift;
91 return $self->{perm} if exists $self->{perm};
92 my @sg = $self->aws->describe_security_groups(-group_id=>$self->groupId);
93 return unless @sg;
94 die "more than one security group returned?" if @sg > 1;
95 return $self->{perm} = $sg[0];
96 }
97  
98 1;
99