File Coverage

blib/lib/Software/Policies.pm
Criterion Covered Total %
statement 41 41 100.0
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 55 56 98.2


line stmt bran cond sub pod time code
1             ## no critic (ControlStructures::ProhibitPostfixControls)
2             package Software::Policies;
3 3     3   1286312 use strict;
  3         7  
  3         118  
4 3     3   19 use warnings;
  3         6  
  3         181  
5 3     3   62 use 5.010;
  3         12  
6              
7             # ABSTRACT: Create policy files: CODE_OF_CONDUCT, CONTRIBUTING, FUNDING, GOVERNANCE, SECURITY, SUPPORT, etc.
8              
9             our $VERSION = '0.002';
10              
11 3     3   1091 use Module::Load qw( load );
  3         3576  
  3         24  
12 3     3   1659 use Module::Loader ();
  3         65045  
  3         1862  
13              
14             sub new {
15 4     4 1 763992 my ($class) = @_;
16 4         10 my %self;
17 4         29 return bless \%self, $class;
18             }
19              
20             sub list {
21 1     1 1 9 my ($self) = @_;
22 1         4 return $self->_get_policies();
23             }
24              
25             sub create {
26 3     3 1 20 my ( $self, %args ) = @_;
27 3         14 my $policy = delete $args{'policy'};
28 3         36 my $module = __PACKAGE__ . q{::} . $policy;
29 3         19 load $module;
30 3         204 my $m = $module->new();
31 3         15 my @r = $m->create(%args);
32 3         36 return @r;
33             }
34              
35             sub _get_policies {
36 1     1   3 my ($self) = @_;
37 1         10 my $loader = Module::Loader->new;
38 1         11 my %policies;
39 1         3 my $this_package = __PACKAGE__;
40             my @policies = grep {
41              
42             # Filter in only immediate child modules, not sub children.
43 1         6 m/^ $this_package :: [^:]{1,} $/msx;
  7         24335  
44             } $loader->find_modules($this_package);
45 1         5 foreach my $policy_module (@policies) {
46 4         34 my ($policy) = $policy_module =~ m/.*::([[:word:]]{1,})$/msx;
47 4 50       27 $policies{$policy} = { classes => {} } if ( !defined $policies{$policy} );
48 4         16 $policies{$policy}->{classes} = $self->_get_policy($policy);
49             }
50 1         17 return \%policies;
51             }
52              
53             sub _get_policy {
54 4     4   9 my ( $self, $policy ) = @_;
55 4         11 my $policy_module = __PACKAGE__ . q{::} . $policy;
56 4         19 load $policy_module;
57 4         73 return $policy_module->get_available_classes_and_versions();
58             }
59              
60             1;
61              
62             __END__