File Coverage

blib/lib/App/Software/License.pm
Criterion Covered Total %
statement 37 40 92.5
branch 4 4 100.0
condition 10 14 71.4
subroutine 10 11 90.9
pod 0 2 0.0
total 61 71 85.9


line stmt bran cond sub pod time code
1             package App::Software::License; # git description: v0.04-6-g4ebad1e
2             # ABSTRACT: Command-line interface to Software::License
3             # KEYWORDS: license licence LICENSE generate distribution build tool
4              
5             our $VERSION = '0.05';
6              
7 3     3   43350 use Moo;
  3         27411  
  3         11  
8 3     3   5404 use MooX::Options;
  3         60158  
  3         13  
9 3     3   184185 use File::HomeDir;
  3         13538  
  3         174  
10 3     3   1018 use File::Spec::Functions qw/catfile/;
  3         1132  
  3         143  
11 3     3   13 use Module::Runtime qw/use_module/;
  3         4  
  3         21  
12 3     3   1227 use Software::License;
  3         21570  
  3         89  
13 3     3   1976 use Config::Any;
  3         16836  
  3         114  
14              
15 3     3   1193 use namespace::autoclean 0.16 -except => [qw/_options_data _options_config/];
  3         20773  
  3         16  
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             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             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             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             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             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                 isa => sub { die "Not a Software::License" if !$_[0]->isa('Software::License') },
134                 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             sub _build__software_license {
145 7     7   1311     my ($self) = @_;
146 7         9     my $class = "Software::License::${\$self->license}";
  7         33  
147              
148 7         21     return use_module($class)->new({
149                     holder => $self->holder,
150                     year => $self->year,
151                 });
152             }
153              
154             sub BUILDARGS {
155 7     7 0 22478     my $class = shift;
156              
157 7         12     my $args = { @_ };
158 7   66     43     my $configfile = $args->{'configfile'} || catfile(File::HomeDir->my_home, '.software_license.conf');
159              
160             # Handling license as a trailing non-option argument
161 7 100 100     214     if(!exists $args->{'license'} && scalar @ARGV && $ARGV[-1] !~ m{^--.+=.+} && (!scalar (@_) || $ARGV[-1] ne $_[-1])) {
      66        
      66        
      66        
162 4         5         $args->{'license'} = $ARGV[-1];
163                 }
164              
165 7 100       122     if(-e $configfile) {
166 2         19         my $conf = Config::Any->load_files({ files => [$configfile], use_ext => 0, flatten_to_hash => 1 })->{ $configfile };
167 2         29905         $args = { %$conf, %$args };
168                 }
169 7         128     return $args;
170             }
171              
172             sub run {
173 0     0 0       my ($self) = @_;
174 0               my $meth = $self->type;
175 0               print $self->_software_license->$meth;
176             }
177              
178             1;
179              
180             __END__
181            
182             =pod
183            
184             =encoding UTF-8
185            
186             =head1 NAME
187            
188             App::Software::License - Command-line interface to Software::License
189            
190             =head1 VERSION
191            
192             version 0.05
193            
194             =head1 SYNOPSIS
195            
196             software-license --holder 'J. Random Hacker' --license Perl_5 --type notice
197            
198             =head1 DESCRIPTION
199            
200             This module provides a command-line interface to Software::License. It can be
201             used to easily produce license notices to be included in other documents.
202            
203             All the attributes documented below are available as command-line options
204             through L<MooX::Options> and can also be configured in
205             F<$HOME/.software_license.conf> through L<Config::Any>.
206            
207             =head1 ATTRIBUTES
208            
209             =head2 holder
210            
211             Name of the license holder.
212            
213             =head2 year
214            
215             Year to be used in the copyright notice.
216            
217             =head2 license
218            
219             Name of the license to use. Must be the name of a module available under the
220             Software::License:: namespace. Defaults to Perl_5.
221            
222             =head2 type
223            
224             The type of license notice you'd like to generate. Available values are:
225            
226             B<* notice>
227            
228             This method returns a snippet of text, usually a few lines, indicating the
229             copyright holder and year of copyright, as well as an indication of the license
230             under which the software is distributed.
231            
232             B<* license>
233            
234             This method returns the full text of the license.
235            
236             =head2 configfile
237            
238             Path to the optional configuration file. Defaults to C<$HOME/.software_license.conf>.
239            
240             =for :stopwords fulltext
241            
242             B<* fulltext>
243            
244             This method returns the complete text of the license, preceded by the copyright
245             notice.
246            
247             B<* version>
248            
249             =for :stopwords versioned
250            
251             This method returns the version of the license. If the license is not
252             versioned, this returns nothing.
253            
254             B<* meta_yml_name>
255            
256             This method returns the string that should be used for this license in the CPAN
257             META.yml file, or nothing if there is no known string to use.
258            
259             =for Pod::Coverage run
260            
261             =for Pod::Coverage BUILDARGS
262            
263             =head1 SUPPORT
264            
265             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=App-Software-License>
266             (or L<bug-App-Software-License@rt.cpan.org|mailto:bug-App-Software-License@rt.cpan.org>).
267            
268             There is also a mailing list available for users of this distribution, at
269             L<http://lists.perl.org/list/cpan-workers.html>.
270            
271             There is also an irc channel available for users of this distribution, at
272             L<C<#toolchain> on C<irc.perl.org>|irc://irc.perl.org/#toolchain>.
273            
274             =head1 AUTHOR
275            
276             Florian Ragwitz <rafl@debian.org>
277            
278             =head1 CONTRIBUTORS
279            
280             =for stopwords Karen Etheridge Randy Stauner Erik Carlsson
281            
282             =over 4
283            
284             =item *
285            
286             Karen Etheridge <ether@cpan.org>
287            
288             =item *
289            
290             Randy Stauner <rwstauner@cpan.org>
291            
292             =item *
293            
294             Erik Carlsson <info@code301.com>
295            
296             =back
297            
298             =head1 COPYRIGHT AND LICENCE
299            
300             This software is copyright (c) 2009 by Florian Ragwitz.
301            
302             This is free software; you can redistribute it and/or modify it under
303             the same terms as the Perl 5 programming language system itself.
304            
305             =cut
306