File Coverage

blib/lib/Chef/REST/Client/environments.pm
Criterion Covered Total %
statement 9 22 40.9
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 2 2 100.0
total 14 36 38.8


line stmt bran cond sub pod time code
1             #--------------------------------------------------------------------#
2             # @class : Chef::Rest::Client::environments #
3             # @author : Bhavin Patel #
4             #--------------------------------------------------------------------#
5              
6             package Chef::REST::Client::environments;
7 1     1   6 use parent qw { Chef::REST::Client::EndPoints };
  1         2  
  1         6  
8              
9 1     1   729 use Chef::REST::Client::environment;
  1         3  
  1         32  
10 1     1   588 use Chef::REST::Client::attributes;
  1         3  
  1         273  
11              
12             $Chef::REST::Client::environments::VERSION = 1.0;
13              
14             # this module will be passed tha json parsed hash
15             # under ___data__() or variable.
16             # process it depending on the content expected.
17              
18             sub list
19             {
20 0     0 1   my $self = shift;
21 0           my $list_of_environments = $self->___data___;
22 0 0         return undef if $self->___data___->{'chef_type'} eq 'environment';
23            
24 0           foreach my $e ( keys(%$list_of_environments) ){
25 0           my $environment = new Chef::REST::Client::environment
26             (
27             'name' => $e,
28             'url' => $list_of_environments->{$e},
29             );
30            
31 0           push @{'___environments_list___'} , $environment;
  0            
32             }
33 0           return @{'___environments_list___'};
  0            
34             }
35              
36             sub details
37             {
38 0     0 1   my $self = shift;
39 0           my $data = $self->___data___;
40              
41 0 0 0       return $self->raw() unless ref $data eq 'HASH' && $data->{'name'};
42 0           return new Chef::REST::Client::environment (
43             'name' => $data->{'name' },
44             'description' => $data->{'description'},
45             'default_attributes' => new Chef::REST::Client::attributes( $data->{'default_attributes' } ),
46             'override_attributes' => new Chef::REST::Client::attributes( $data->{'override_attributes'} ),
47             'cookbook_versions' => $data->{'cookbook_versions'}
48             );
49             }
50            
51             1;
52              
53             =pod
54              
55             =head1 NAME
56              
57             Chef::REST::Client::environments
58              
59             =head1 VERSION
60              
61             1.0
62              
63             =head1 SYNOPSIS
64              
65             use Chef::REST::Client::environments;
66              
67             $obj->environments->list;
68             $obj->environments('dev')->details;
69            
70             =head1 DESCRIPTION
71              
72             Class that represents collection of environments
73              
74             =head1 METHODS
75              
76             =head2 list
77              
78             return list of environments, array of L objects.
79              
80             =head2 details ( $details )
81              
82             retun detail about a perticular environment.
83              
84             =head1 KNOWN BUGS
85              
86             =head1 SUPPORT
87              
88             open a github ticket or email comments to Bhavin Patel
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This Software is free to use , licensed under : The Artisic License 2.0 (GPL Compatible)
93              
94             =cut