File Coverage

blib/lib/Software/Policies/License.pm
Criterion Covered Total %
statement 15 39 38.4
branch 0 10 0.0
condition 0 11 0.0
subroutine 6 9 66.6
pod 3 3 100.0
total 24 72 33.3


line stmt bran cond sub pod time code
1             ## no critic (ControlStructures::ProhibitPostfixControls)
2             package Software::Policies::License;
3              
4 2     2   4359 use strict;
  2         8  
  2         92  
5 2     2   10 use warnings;
  2         4  
  2         139  
6 2     2   41 use 5.010;
  2         7  
7              
8             # ABSTRACT: Create project policy file: License
9              
10             our $VERSION = '0.002';
11              
12 2     2   16 use Carp;
  2         4  
  2         192  
13 2     2   21 use Module::Load qw( load );
  2         4  
  2         16  
14              
15             # use Software::License;
16              
17             sub new {
18 0     0 1 0 my ($class) = @_;
19 0         0 return bless {}, $class;
20             }
21              
22             sub create {
23 0     0 1 0 my ( $self, %args ) = @_;
24 0   0     0 my $class = $args{'class'} // 'Perl_5';
25 0   0     0 my $version = $args{'version'} // '1';
26 0   0     0 my $format = $args{'format'} // 'text';
27 0         0 my %attributes;
28 0   0     0 my $attrs = $args{'attributes'} // {};
29 0 0       0 $attributes{'holder'} = $attrs->{'authors'}->[0] if $attrs->{'authors'};
30 0 0       0 $attributes{'year'} = $attrs->{'year'} if $attrs->{'year'};
31             $attributes{'perl_5_double_license'} = $attrs->{'perl_5_double_license'}
32 0 0       0 if $attrs->{'perl_5_double_license'};
33             croak q{Missing attribute 'holder'}
34 0 0       0 if ( !defined $attributes{'holder'} );
35 0         0 my $txt;
36              
37 0 0 0     0 if ( $class eq 'Perl_5' && $attributes{'perl_5_double_license'} ) {
38 0         0 load 'Software::License::GPL_3'; # filename: LICENSE-GPL-3
39 0         0 load 'Software::License::Artistic_2_0'; # filename: LICENSE-Artistic-2.0
40             return {
41 0         0 policy => __PACKAGE__ =~ m/.*::([[:word:]]{1,})$/msx,
42             class => 'GPL',
43             version => 1,
44             text => Software::License::GPL_3->new( \%attributes )->license,
45             filename => 'LICENSE-GPL-3',
46             format => 'text',
47             },
48             {
49             policy => __PACKAGE__ =~ m/.*::([[:word:]]{1,})$/msx,
50             class => 'Artistic',
51             version => '1.0',
52             text => Software::License::Artistic_2_0->new( \%attributes )->license,
53             filename => 'LICENSE-Artistic-2.0',
54             format => 'text',
55             };
56             }
57             else {
58 0         0 my $module = 'Software::License::' . $class;
59 0         0 load $module;
60 0         0 $txt = $module->new( \%attributes );
61             }
62             return {
63 0         0 policy => __PACKAGE__ =~ m/.*::([[:word:]]{1,})$/msx,
64             class => $class,
65             version => $version,
66             text => $txt->license,
67             filename => _filename($format),
68             format => $format,
69             };
70             }
71              
72             sub get_available_classes_and_versions {
73             return {
74 1     1 1 13 'Perl_5' => {
75             versions => {
76             '1' => 1,
77             },
78             formats => {
79             'text' => 1,
80             },
81             },
82             };
83             }
84              
85             sub _filename {
86 0     0     my ($format) = @_;
87 0           my %formats = ( 'text' => 'LICENSE', );
88 0           return $formats{$format};
89             }
90              
91             1;
92              
93             __END__