File Coverage

blib/lib/Software/License.pm
Criterion Covered Total %
statement 32 45 71.1
branch 8 18 44.4
condition 6 6 100.0
subroutine 16 20 80.0
pod 12 13 92.3
total 74 102 72.5


line stmt bran cond sub pod time code
1 15     15   78766 use strict;
  15         47  
  15         445  
2 15     15   76 use warnings;
  15         32  
  15         363  
3 15     15   368 use 5.006; # warnings
  15         54  
4             package Software::License;
5             # ABSTRACT: packages that provide templated software licenses
6             $Software::License::VERSION = '0.104001';
7 15     15   8155 use Data::Section -setup => { header_re => qr/\A__([^_]+)__\Z/ };
  15         441155  
  15         198  
8 15     15   24200 use Text::Template ();
  15         60603  
  15         11663  
9              
10             #pod =head1 SYNOPSIS
11             #pod
12             #pod my $license = Software::License::Discordian->new({
13             #pod holder => 'Ricardo Signes',
14             #pod });
15             #pod
16             #pod print $output_fh $license->fulltext;
17             #pod
18             #pod =method new
19             #pod
20             #pod my $license = $subclass->new(\%arg);
21             #pod
22             #pod This method returns a new license object for the given license class. Valid
23             #pod arguments are:
24             #pod
25             #pod =for :list
26             #pod = holder
27             #pod the holder of the copyright; required
28             #pod = year
29             #pod the year of copyright; defaults to current year
30             #pod = program
31             #pod the name of software for use in the middle of a sentence
32             #pod = Program
33             #pod the name of software for use in the beginning of a sentence
34             #pod
35             #pod C and C arguments may be specified both, either one or none.
36             #pod Each argument, if not specified, is defaulted to another one, or to properly
37             #pod capitalized "this program", if both arguments are omitted.
38             #pod
39             #pod =cut
40              
41             sub new {
42 52     52 1 37342 my ($class, $arg) = @_;
43              
44 52 50       307 Carp::croak "no copyright holder specified" unless $arg->{holder};
45              
46 52         245 bless $arg => $class;
47             }
48              
49             #pod =method year
50             #pod
51             #pod =method holder
52             #pod
53             #pod These methods are attribute readers.
54             #pod
55             #pod =cut
56              
57 56 100   56 1 37650 sub year { defined $_[0]->{year} ? $_[0]->{year} : (localtime)[5]+1900 }
58 58     58 1 2336 sub holder { $_[0]->{holder} }
59              
60             sub _dotless_holder {
61 45     45   4352 my $holder = $_[0]->holder;
62 45         282 $holder =~ s/\.$//;
63 45         334 return $holder;
64             }
65              
66             #pod =method program
67             #pod
68             #pod Name of software for using in the middle of a sentence.
69             #pod
70             #pod The method returns value of C constructor argument (if it evaluates as true, i. e.
71             #pod defined, non-empty, non-zero), or value of C constructor argument (if it is true), or
72             #pod "this program" as the last resort.
73             #pod
74             #pod =cut
75              
76 4 100 100 4 1 43 sub program { $_[0]->{program} || $_[0]->{Program} || 'this program' }
77              
78             #pod =method Program
79             #pod
80             #pod Name of software for using in the middle of a sentence.
81             #pod
82             #pod The method returns value of C constructor argument (if it is true), or value of C
83             #pod constructor argument (if it is true), or "This program" as the last resort.
84             #pod
85             #pod =cut
86              
87 4 100 100 4 1 30 sub Program { $_[0]->{Program} || $_[0]->{program} || 'This program' }
88              
89             #pod =method name
90             #pod
91             #pod This method returns the name of the license, suitable for shoving in the middle
92             #pod of a sentence, generally with a leading capitalized "The."
93             #pod
94             #pod =method url
95             #pod
96             #pod This method returns the URL at which a canonical text of the license can be
97             #pod found, if one is available. If possible, this will point at plain text, but it
98             #pod may point to an HTML resource.
99             #pod
100             #pod =method notice
101             #pod
102             #pod This method returns a snippet of text, usually a few lines, indicating the
103             #pod copyright holder and year of copyright, as well as an indication of the license
104             #pod under which the software is distributed.
105             #pod
106             #pod =cut
107              
108 46     46 1 384 sub notice { shift->_fill_in('NOTICE') }
109              
110             #pod =method license
111             #pod
112             #pod This method returns the full text of the license.
113             #pod
114             #pod =cut
115              
116 36     36 1 23345 sub license { shift->_fill_in('LICENSE') }
117              
118             #pod =method fulltext
119             #pod
120             #pod This method returns the complete text of the license, preceded by the copyright
121             #pod notice.
122             #pod
123             #pod =cut
124              
125             sub fulltext {
126 8     8 1 29 my ($self) = @_;
127 8         39 return join "\n", $self->notice, $self->license;
128             }
129              
130             #pod =method version
131             #pod
132             #pod This method returns the version of the license. If the license is not
133             #pod versioned, this method will return false.
134             #pod
135             #pod =cut
136              
137             sub version {
138 0     0 1 0 my ($self) = @_;
139 0 0       0 my $pkg = ref $self ? ref $self : $self;
140 0         0 $pkg =~ s/.+:://;
141 0         0 my (undef, @vparts) = split /_/, $pkg;
142              
143 0 0       0 return unless @vparts;
144 0         0 return join '.', @vparts;
145             }
146              
147             #pod =method meta_name
148             #pod
149             #pod This method returns the string that should be used for this license in the CPAN
150             #pod META.yml file, according to the CPAN Meta spec v1, or undef if there is no
151             #pod known string to use.
152             #pod
153             #pod This method may also be invoked as C for legacy reasons.
154             #pod
155             #pod =method meta2_name
156             #pod
157             #pod This method returns the string that should be used for this license in the CPAN
158             #pod META.json or META.yml file, according to the CPAN Meta spec v2, or undef if
159             #pod there is no known string to use. If this method does not exist, and
160             #pod C returns open_source, restricted, unrestricted, or unknown, that
161             #pod value will be used.
162             #pod
163             #pod =cut
164              
165             # sub meta1_name { return undef; } # sort this out later, should be easy
166 0     0 1 0 sub meta_name { return undef; }
167 0     0 0 0 sub meta_yml_name { $_[0]->meta_name }
168              
169             sub meta2_name {
170 0     0 1 0 my ($self) = @_;
171 0         0 my $meta1 = $self->meta_name;
172              
173 0 0       0 return undef unless defined $meta1;
174              
175 0 0       0 return $meta1
176             if $meta1 =~ /\A(?:open_source|restricted|unrestricted|unknown)\z/;
177              
178 0         0 return undef;
179             }
180              
181             #pod =method spdx_expression
182             #pod
183             #pod This method should return the string with the spdx identifier as indicated by
184             #pod L
185             #pod
186             #pod =cut
187              
188 21     21 1 67 sub spdx_expression { return undef; }
189              
190             sub _fill_in {
191 113     113   320 my ($self, $which) = @_;
192              
193 113 50       536 Carp::confess "couldn't build $which section" unless
194             my $template = $self->section_data($which);
195              
196 92         604847 return Text::Template->fill_this_in(
197             $$template,
198             HASH => { self => \$self },
199             DELIMITERS => [ qw({{ }}) ],
200             );
201             }
202              
203             #pod =head1 LOOKING UP LICENSE CLASSES
204             #pod
205             #pod If you have an entry in a F or F file, or similar
206             #pod metadata, and want to look up the Software::License class to use, there are
207             #pod useful tools in L.
208             #pod
209             #pod =head1 TODO
210             #pod
211             #pod =for :list
212             #pod * register licenses with aliases to allow $registry->get('gpl', 2);
213             #pod
214             #pod =head1 SEE ALSO
215             #pod
216             #pod The specific license:
217             #pod
218             #pod =for :list
219             #pod * L
220             #pod * L
221             #pod * L
222             #pod * L
223             #pod * L
224             #pod * L
225             #pod * L
226             #pod * L
227             #pod * L
228             #pod * L
229             #pod * L
230             #pod * L
231             #pod * L
232             #pod * L
233             #pod * L
234             #pod * L
235             #pod * L
236             #pod * L
237             #pod * L
238             #pod * L
239             #pod * L
240             #pod * L
241             #pod * L
242             #pod * L
243             #pod * L
244             #pod * L
245             #pod * L
246             #pod * L
247             #pod * L
248             #pod * L
249             #pod
250             #pod Extra licenses are maintained on CPAN in separate modules.
251             #pod
252             #pod The L module comes with a script
253             #pod L,
254             #pod which provides a command-line interface
255             #pod to Software::License.
256             #pod
257             #pod =cut
258              
259             1;
260              
261             =pod
262              
263             =encoding UTF-8
264              
265             =head1 NAME
266              
267             Software::License - packages that provide templated software licenses
268              
269             =head1 VERSION
270              
271             version 0.104001
272              
273             =head1 SYNOPSIS
274              
275             my $license = Software::License::Discordian->new({
276             holder => 'Ricardo Signes',
277             });
278              
279             print $output_fh $license->fulltext;
280              
281             =head1 METHODS
282              
283             =head2 new
284              
285             my $license = $subclass->new(\%arg);
286              
287             This method returns a new license object for the given license class. Valid
288             arguments are:
289              
290             =over 4
291              
292             =item holder
293              
294             the holder of the copyright; required
295              
296             =item year
297              
298             the year of copyright; defaults to current year
299              
300             =item program
301              
302             the name of software for use in the middle of a sentence
303              
304             =item Program
305              
306             the name of software for use in the beginning of a sentence
307              
308             =back
309              
310             C and C arguments may be specified both, either one or none.
311             Each argument, if not specified, is defaulted to another one, or to properly
312             capitalized "this program", if both arguments are omitted.
313              
314             =head2 year
315              
316             =head2 holder
317              
318             These methods are attribute readers.
319              
320             =head2 program
321              
322             Name of software for using in the middle of a sentence.
323              
324             The method returns value of C constructor argument (if it evaluates as true, i. e.
325             defined, non-empty, non-zero), or value of C constructor argument (if it is true), or
326             "this program" as the last resort.
327              
328             =head2 Program
329              
330             Name of software for using in the middle of a sentence.
331              
332             The method returns value of C constructor argument (if it is true), or value of C
333             constructor argument (if it is true), or "This program" as the last resort.
334              
335             =head2 name
336              
337             This method returns the name of the license, suitable for shoving in the middle
338             of a sentence, generally with a leading capitalized "The."
339              
340             =head2 url
341              
342             This method returns the URL at which a canonical text of the license can be
343             found, if one is available. If possible, this will point at plain text, but it
344             may point to an HTML resource.
345              
346             =head2 notice
347              
348             This method returns a snippet of text, usually a few lines, indicating the
349             copyright holder and year of copyright, as well as an indication of the license
350             under which the software is distributed.
351              
352             =head2 license
353              
354             This method returns the full text of the license.
355              
356             =head2 fulltext
357              
358             This method returns the complete text of the license, preceded by the copyright
359             notice.
360              
361             =head2 version
362              
363             This method returns the version of the license. If the license is not
364             versioned, this method will return false.
365              
366             =head2 meta_name
367              
368             This method returns the string that should be used for this license in the CPAN
369             META.yml file, according to the CPAN Meta spec v1, or undef if there is no
370             known string to use.
371              
372             This method may also be invoked as C for legacy reasons.
373              
374             =head2 meta2_name
375              
376             This method returns the string that should be used for this license in the CPAN
377             META.json or META.yml file, according to the CPAN Meta spec v2, or undef if
378             there is no known string to use. If this method does not exist, and
379             C returns open_source, restricted, unrestricted, or unknown, that
380             value will be used.
381              
382             =head2 spdx_expression
383              
384             This method should return the string with the spdx identifier as indicated by
385             L
386              
387             =head1 LOOKING UP LICENSE CLASSES
388              
389             If you have an entry in a F or F file, or similar
390             metadata, and want to look up the Software::License class to use, there are
391             useful tools in L.
392              
393             =head1 TODO
394              
395             =over 4
396              
397             =item *
398              
399             register licenses with aliases to allow $registry->get('gpl', 2);
400              
401             =back
402              
403             =head1 SEE ALSO
404              
405             The specific license:
406              
407             =over 4
408              
409             =item *
410              
411             L
412              
413             =item *
414              
415             L
416              
417             =item *
418              
419             L
420              
421             =item *
422              
423             L
424              
425             =item *
426              
427             L
428              
429             =item *
430              
431             L
432              
433             =item *
434              
435             L
436              
437             =item *
438              
439             L
440              
441             =item *
442              
443             L
444              
445             =item *
446              
447             L
448              
449             =item *
450              
451             L
452              
453             =item *
454              
455             L
456              
457             =item *
458              
459             L
460              
461             =item *
462              
463             L
464              
465             =item *
466              
467             L
468              
469             =item *
470              
471             L
472              
473             =item *
474              
475             L
476              
477             =item *
478              
479             L
480              
481             =item *
482              
483             L
484              
485             =item *
486              
487             L
488              
489             =item *
490              
491             L
492              
493             =item *
494              
495             L
496              
497             =item *
498              
499             L
500              
501             =item *
502              
503             L
504              
505             =item *
506              
507             L
508              
509             =item *
510              
511             L
512              
513             =item *
514              
515             L
516              
517             =item *
518              
519             L
520              
521             =item *
522              
523             L
524              
525             =item *
526              
527             L
528              
529             =back
530              
531             Extra licenses are maintained on CPAN in separate modules.
532              
533             The L module comes with a script
534             L,
535             which provides a command-line interface
536             to Software::License.
537              
538             =head1 AUTHOR
539              
540             Ricardo Signes
541              
542             =head1 CONTRIBUTORS
543              
544             =for stopwords Alex Kapranoff Andrew Grangaard Axel Beckert Bernardo Rechea Bernhard Amann bowtie Brian Cassidy Phillips Craig Scrivner Curtis Brandt Dave Rolsky David E. Wheeler Golden Dominique Dumont Dylan William Hardison Flavio Poletti Florian Ragwitz Graham Knop Kang-min Liu Karen Etheridge Kenichi Ishigaki Kivanc Yazan Leon Timmermans magnolia mikegrb Neil Bowers Nicolas Rochelemagne Olivier Mengué Pablo Rodríguez González Shlomi Fish Syohei YOSHIDA Tomasz Konojacki Van de Bugger Wesley Schwengle
545              
546             =over 4
547              
548             =item *
549              
550             Alex Kapranoff
551              
552             =item *
553              
554             Andrew Grangaard
555              
556             =item *
557              
558             Axel Beckert
559              
560             =item *
561              
562             Bernardo Rechea
563              
564             =item *
565              
566             Bernhard Amann
567              
568             =item *
569              
570             bowtie
571              
572             =item *
573              
574             Brian Cassidy
575              
576             =item *
577              
578             Brian Phillips
579              
580             =item *
581              
582             Craig Scrivner
583              
584             =item *
585              
586             Curtis Brandt
587              
588             =item *
589              
590             Dave Rolsky
591              
592             =item *
593              
594             David E. Wheeler
595              
596             =item *
597              
598             David Golden
599              
600             =item *
601              
602             Dominique Dumont
603              
604             =item *
605              
606             Dylan William Hardison
607              
608             =item *
609              
610             Flavio Poletti
611              
612             =item *
613              
614             Florian Ragwitz
615              
616             =item *
617              
618             Graham Knop
619              
620             =item *
621              
622             Kang-min Liu
623              
624             =item *
625              
626             Karen Etheridge
627              
628             =item *
629              
630             Kenichi Ishigaki
631              
632             =item *
633              
634             Kivanc Yazan
635              
636             =item *
637              
638             Leon Timmermans
639              
640             =item *
641              
642             magnolia
643              
644             =item *
645              
646             mikegrb
647              
648             =item *
649              
650             Neil Bowers
651              
652             =item *
653              
654             Nicolas Rochelemagne
655              
656             =item *
657              
658             Olivier Mengué
659              
660             =item *
661              
662             Pablo Rodríguez González
663              
664             =item *
665              
666             Shlomi Fish
667              
668             =item *
669              
670             Syohei YOSHIDA
671              
672             =item *
673              
674             Tomasz Konojacki
675              
676             =item *
677              
678             Van de Bugger
679              
680             =item *
681              
682             Wesley Schwengle
683              
684             =back
685              
686             =head1 COPYRIGHT AND LICENSE
687              
688             This software is copyright (c) 2021 by Ricardo Signes.
689              
690             This is free software; you can redistribute it and/or modify it under
691             the same terms as the Perl 5 programming language system itself.
692              
693             =cut
694              
695             __DATA__