blib/lib/App/Software/License.pm

filter: Statementstmt 94.0% 47 / 50 Branchbran 83.3% 5 / 6 Conditioncond 81.2% 13 / 16 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 84.9% 79 / 93 CC 10 SCAR 15.3
CC
10
Cov
90%
BUILDARGS
9.1
__ANON__
2.1
run
2.0
CRAP 4.6
↑ Summary
1 package App::Software::License; # git description: v0.10-4-g9e7e1ff
2 # ABSTRACT: Command-line interface to Software::License
3 # KEYWORDS: license licence LICENSE generate distribution build tool
4  
5 3 our $VERSION = '0.11';
6  
7 3 ▶use Moo 1.001000;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Spec::Functions qw/catfile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Module::Runtime qw/use_module/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Software::License;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use namespace::autoclean 0.16 -except => [qw/_options_data _options_config/];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #pod =head1 SYNOPSIS
18 #pod
19 #pod software-license --holder 'J. Random Hacker' --license Perl_5 --type notice
20 #pod
21 #pod =head1 DESCRIPTION
22 #pod
23 #pod This module provides a command-line interface to Software::License. It can be
24 #pod used to easily produce license notices to be included in other documents.
25 #pod
26 #pod All the attributes documented below are available as command-line options
27 #pod through L<MooX::Options> and can also be configured in
28 #pod F<$HOME/.software_license.conf> through L<Config::Any>.
29 #pod
30 #pod =cut
31  
32 #pod =attr holder
33 #pod
34 #pod Name of the license holder.
35 #pod
36 #pod =cut
37  
38 3 option holder => (
39 is => 'ro',
40 required => 1,
41 format => 's',
42 doc => '',
43 );
44  
45 #pod =attr year
46 #pod
47 #pod Year to be used in the copyright notice.
48 #pod
49 #pod =cut
50  
51 3 option year => (
52 is => 'ro',
53 format => 'i',
54 doc => '',
55 );
56  
57 #pod =attr license
58 #pod
59 #pod Name of the license to use. Must be the name of a module available under the
60 #pod Software::License:: namespace. Defaults to Perl_5.
61 #pod
62 #pod =cut
63  
64 3 option license => (
65 is => 'ro',
66 default => 'Perl_5',
67 format => 's',
68 doc => '',
69 );
70  
71 #pod =attr type
72 #pod
73 #pod The type of license notice you'd like to generate. Available values are:
74 #pod
75 #pod B<* notice>
76 #pod
77 #pod This method returns a snippet of text, usually a few lines, indicating the
78 #pod copyright holder and year of copyright, as well as an indication of the license
79 #pod under which the software is distributed.
80 #pod
81 #pod B<* license>
82 #pod
83 #pod This method returns the full text of the license.
84 #pod
85 #pod =for :stopwords fulltext
86 #pod
87 #pod B<* fulltext>
88 #pod
89 #pod This method returns the complete text of the license, preceded by the copyright
90 #pod notice.
91 #pod
92 #pod B<* version>
93 #pod
94 #pod =for :stopwords versioned
95 #pod
96 #pod This method returns the version of the license. If the license is not
97 #pod versioned, this returns nothing.
98 #pod
99 #pod B<* meta_yml_name>
100 #pod
101 #pod This method returns the string that should be used for this license in the CPAN
102 #pod META.yml file, or nothing if there is no known string to use.
103 #pod
104 #pod =for Pod::Coverage run
105 #pod
106 #pod =for Pod::Coverage BUILDARGS
107 #pod
108 #pod =cut
109  
110 3 option type => (
111 is => 'ro',
112 default => 'notice',
113 format => 's',
114 doc => '',
115 );
116  
117 #pod =attr configfile
118 #pod
119 #pod Path to the optional configuration file. Defaults to C<$HOME/.software_license.conf>.
120 #pod
121 #pod =cut
122  
123 3 option configfile => (
124 is => 'ro',
125 default => catfile(File::HomeDir->my_home, '.software_license.conf'),
126 format => 's',
127 doc => '',
128 order => 100,
129 );
130  
131 has _software_license => (
132 is => 'ro',
133 7 ▶ isa => sub { die "Not a Software::License" if !$_[0]->isa('Software::License') },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0]->isa("Software::License") 0 7 7
134 3 lazy => 1,
135 builder => '_build__software_license',
136 handles => {
137 notice => 'notice',
138 text => 'license',
139 fulltext => 'fulltext',
140 version => 'version',
141 },
142 );
143  
144 7 ▶sub _build__software_license {
Subroutine _build__software_license: called CC=1 SCAR=0.0
145 7 my ($self) = @_;
146 7 my $class = "Software::License::${\$self->license}";
147  
148 7 return use_module($class)->new({
149 holder => $self->holder,
150 year => $self->year,
151 });
152 }
153  
154 7 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=9 SCAR=22.1
Pod undocumented
155 7 my $class = shift;
156  
157 7 my $args = { @_ };
158 7 ▶ my $configfile = $args->{configfile} || catfile(File::HomeDir->my_home, '.software_license.conf');
Condition66%2/3
$args->{'configfile'} || catfile('File::HomeDir'->my_home, '.software_license.conf')
l!l&&r!l&&!r
250
MC/DC0%0/2
$args->{'configfile'} || catfile('File::HomeDir'->my_home, '.software_license.conf')
$args->{'configfile'} catfile('File::HomeDir'->my_home, '.software_license.conf')
Truth table66%2/3
A || B
A= $args->{'configfile'}B= catfile('File::HomeDir'->my_home, '.software_license.conf')
ABresult
1X1
011
000
159  
160 # Handling license as a trailing non-option argument
161 7 ▶ if (!exists $args->{license}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args->{"license"} and scalar @ARGV and not $ARGV[-1] =~ /^--.+=.+/ and !scalar(@_) || $ARGV[-1] ne $_[-1]) 4 3 7
Condition90%10/11
not exists $args->{"license"} and scalar @ARGV and not $ARGV[-1] =~ /^--.+=.+/ and !scalar(@_) || $ARGV[-1] ne $_[-1]
!ll&&!rl&&r
214
not exists $args->{"license"} and scalar @ARGV and not $ARGV[-1] =~ /^--.+=.+/
!ll&&!rl&&r
115
not exists $args->{"license"} and scalar @ARGV
!ll
16
not scalar @_ or $ARGV[-1] ne $_[-1]
l!l&&r!l&&!r
041
MC/DC75%3/4
not exists $args->{"license"} and scalar @ARGV and not $ARGV[-1] =~ /^--.+=.+/ and !scalar(@_) || $ARGV[-1] ne $_[-1]
not exists $args->{"license"} not $ARGV[-1] =~ /^--.+=.+/ not scalar @_ $ARGV[-1] ne $_[-1]
Truth table80%4/5
not(A) and not(B) and not(C) or D
A= not exists $args->{"license"}B= not $ARGV[-1] =~ /^--.+=.+/C= not scalar @_D= $ARGV[-1] ne $_[-1]
ABCDresult
0XXX0
10XX0
11000
111X1
11011
162 && scalar @ARGV && $ARGV[-1] !~ m{^--.+=.+}
163 && (!scalar (@_) || $ARGV[-1] ne $_[-1])
164 ) {
165 4 $args->{license} = $ARGV[-1];
166 }
167  
168 7 ▶ if (-e $configfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $configfile) 2 5 7
169 2 my $conf = Config::Any->load_files({ files => [$configfile], use_ext => 1, flatten_to_hash => 1 })->{ $configfile };
170 2 ▶ $args = { %{ $conf || {} }, %$args };
Condition50%1/2
$conf || {}
l!l
20
MC/DC0%0/1
$conf || {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
171 }
172 7 return $args;
173 }
174  
175 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
176 0 my ($self) = @_;
177 0 my $meth = $self->type;
178 0 print $self->_software_license->$meth;
179 }
180  
181 3 1;
182  
183 __END__
↑ Summary