CCfnX/DeployerResourceTypeHandler.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 1 Podpod n/a totaltotal 0.0% 0 / 31 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
CRAP 2.0
1 package CCfnX::DeployerResourceTypeHandler {
2  
3 use MooseX::Role::Parameterized;
4  
5 parameter resource_type_prefixes => (
6 is=>'ro',
7 isa=>'ArrayRef[Str]'
8 );
9  
10 role {
11 my $parameters = shift;
12  
13 my $resource_type_prefixes = $parameters->resource_type_prefixes;
14  
15 method 'can_handle_stack' => sub {
16 my ($self,$stack_resources) = @_;
17  
18 my $can_handle_stack_result = 1;
19 while(my ($resource_name,$resource) = each(%$stack_resources)){
20 if(not $self->can_handle_resource($resource)) {
21 $can_handle_stack_result = 0;
22 last;
23 }
24 }
25  
26 return $can_handle_stack_result;
27 };
28  
29 method 'can_handle_resource' => sub {
30 my ($self,$resource) = @_;
31  
32 my $can_handle_resource_result = 0;
33  
34 for my $resource_type_prefix (@{$resource_type_prefixes}) {
35 if($resource->Type =~ /^${resource_type_prefix}/) {
36 $can_handle_resource_result = 1;
37 last;
38 }
39 }
40  
41 return $can_handle_resource_result;
42 };
43  
44 };
45 }
46  
47 return 1;
48  
49 =head1 NAME
50  
51 CCfnX::DeployerResourceTypeHandler
52  
53 =head1 DESCRIPTION
54  
55 This role is to be applied to Deployers as a security mechanism to prevent deployers from trying to deploy resources they cannot
56 handle. While they may fail immediately, they can cause difficult to debug and repair half-complete states.
57  
58 The philosophy is that a Deployer should get to act on a Stack if it can deploy all of its resources.
59  
60 Remember that a deployer does not need to deploy itself the resources it handles, but can delegate to other deployers if needed.
61 This role exists as a bridge between the old way of doing deployers and the new C<DeploymentEngine> that will dispatch resources to
62 deployment engines. Thus, the deployment engine deployer will handle of type of resources except for AWS CloudFormation resources
63 which are still handled by the C<CloudFormationDeployer> until the C<CloudFormationDeployer> is transformed to a C<DeploymentEngine> C<Engine>.
64  
65 =head1 USAGE
66  
67 package SomeSystemDeployer {
68 use Moose;
69  
70 with 'CCfnX::DeployerResourceTypeHandler' => {
71 resource_type_prefixes => [
72 'Monitoring',
73 'Azure'
74 ]
75 };
76  
77 before 'deploy' => sub {
78 #do something
79 };
80 }
81  
82 =head1 PARAMETERS
83  
84 =head2 resource_type_prefixes
85  
86 Defines what type of resources this deployer can handle. The prefixes of the package names of the resources it can handle.
87 For example, if it can handle AWS::* and Azure::* resources, the prefixes would be [ 'AWS', 'Azure' ].
88  
89 =head1 METHODS
90  
91 =head2 can_handle_stack
92  
93 For a given set of resources, this method returns whether this deployer can handle all resources from this stack.
94 A resource is an object that extends C<Cfn::Resource>.
95  
96 =head3 arguments
97  
98 =head4 stack_resources
99  
100 An ArrayRef of C<Cfn:Resource>
101  
102 =head2 can_handle_resource
103  
104 For a given resource, this method returns whether this deployer can handle it.
105 A resource is an object that extends C<Cfn::Resource>.
106  
107 =head3 arguments
108  
109 =head4 resource
110  
111 A C<Cfn:Resource>
112