File Coverage

blib/lib/Cfn/ResourceModules.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod 2 2 100.0
total 20 21 95.2


line stmt bran cond sub pod time code
1             package Cfn::ResourceModules;
2              
3             sub list {
4 1     1 1 599 require Module::Find;
5 1         1465 my @list = Module::Find::findallmod Cfn::Resource;
6             # strip off the Cfn::Resource
7 1         230946 @list = map { $_ =~ s/^Cfn::Resource:://; $_ } @list;
  506         982  
  506         798  
8 1         60 return @list;
9             }
10              
11 22     22   70050 use Module::Runtime qw//;
  22         1830  
  22         2084  
12             sub load {
13 2226     2226 1 173077 my $type = shift;
14 2226         7202 my $cfn_resource_class = "Cfn::Resource::$type";
15 2226         8626 my $retval = Module::Runtime::require_module($cfn_resource_class);
16 2226 50       47326 die "Couldn't load $cfn_resource_class" if (not $retval);
17 2226         8804 return $cfn_resource_class;
18             }
19              
20             1;
21             ### main pod documentation begin ###
22              
23             =encoding UTF-8
24              
25             =head1 NAME
26              
27             Cfn::ResourceModules - Load Cfn resource classes
28              
29             =head1 SYNOPSIS
30              
31             use Cfn::ResourceModules;
32              
33             my $perl_class = Cfn::ResourceModules::load('AWS::EC2::Instance');
34             my $ec2_instance_object = $perl_class->new(...);
35              
36             my @supported_modules = Cfn::ResourceModules::list;
37              
38             =head1 DESCRIPTION
39              
40             This module is designed to load Perl modules that respresent CloudFormation resources.
41              
42             It exposes functions for knowing what resources are available on the system (what CloudFormation
43             resource types can be loaded) and making them available to your programs. It doesn't export
44             anything into the callers namespace.
45              
46             =head1 FUNCTIONS
47              
48             =head2 list
49              
50             Returns an array of CloudFormation resource types present on the system that can be passed to C<load>
51              
52             =head2 load($resource)
53              
54             When passed a CloudFormation resource type (f.ex. C<AWS::EC2::SecurityGroup>) it loads into memory the
55             Perl modules that will later let the program instance objects of that type. Note that the Perl class
56             for the resource type will get returned (Cfn resource objects are in the C<Cfn::Resource>
57             namespace), so you will get strings of the form C<Cfn::Resource::AWS::EC2::SecurityGroup>.
58              
59             =head1 AUTHOR
60              
61             Jose Luis Martinez
62             CAPSiDE
63             jlmartinez@capside.com
64              
65             =head1 COPYRIGHT and LICENSE
66              
67             Copyright (c) 2013 by CAPSiDE
68             This code is distributed under the Apache 2 License. The full text of the
69             license can be found in the LICENSE file included with this module.
70              
71             =cut