File Coverage

blib/lib/Software/License.pm
Criterion Covered Total %
statement 30 43 69.7
branch 6 16 37.5
condition 8 9 88.8
subroutine 15 19 78.9
pod 12 13 92.3
total 71 100 71.0


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