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   71708 use strict;
  15         46  
  15         418  
2 15     15   73 use warnings;
  15         31  
  15         363  
3 15     15   287 use 5.006; # warnings
  15         55  
4             package Software::License;
5             # ABSTRACT: packages that provide templated software licenses
6             $Software::License::VERSION = '0.104004';
7 15     15   7808 use Data::Section -setup => { header_re => qr/\A__([^_]+)__\Z/ };
  15         405857  
  15         180  
8 15     15   22131 use Text::Template ();
  15         55988  
  15         11069  
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 38113 my ($class, $arg) = @_;
43              
44 52 50       212 Carp::croak "no copyright holder specified" unless $arg->{holder};
45              
46 52         215 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 35853 sub year { defined $_[0]->{year} ? $_[0]->{year} : (localtime)[5]+1900 }
58 58     58 1 2185 sub holder { $_[0]->{holder} }
59              
60             sub _dotless_holder {
61 45     45   4267 my $holder = $_[0]->holder;
62 45         288 $holder =~ s/\.$//;
63 45         367 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 50 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 27 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 362 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 20952 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 23 my ($self) = @_;
127 8         42 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 71 sub spdx_expression { return undef; }
189              
190             sub _fill_in {
191 113     113   286 my ($self, $which) = @_;
192              
193 113 50       444 Carp::confess "couldn't build $which section" unless
194             my $template = $self->section_data($which);
195              
196 92         594114 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 * L
250             #pod
251             #pod Extra licenses are maintained on CPAN in separate modules.
252             #pod
253             #pod The L module comes with a script
254             #pod L,
255             #pod which provides a command-line interface
256             #pod to Software::License.
257             #pod
258             #pod =cut
259              
260             1;
261              
262             =pod
263              
264             =encoding UTF-8
265              
266             =head1 NAME
267              
268             Software::License - packages that provide templated software licenses
269              
270             =head1 VERSION
271              
272             version 0.104004
273              
274             =head1 SYNOPSIS
275              
276             my $license = Software::License::Discordian->new({
277             holder => 'Ricardo Signes',
278             });
279              
280             print $output_fh $license->fulltext;
281              
282             =head1 PERL VERSION
283              
284             This module is part of CPAN toolchain, or is treated as such. As such, it
285             follows the agreement of the Perl Toolchain Gang to require no newer version
286             of perl than one released in the last ten years. This version may change by
287             agreement of the Toolchain Gang, but for now is governed by the L
288             Consensus|https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>
289             of 2013 and the Lyon Amendment of 2023 (described at the linked-to document).
290              
291             Although it may work on older versions of perl, no guarantee is made that the
292             minimum required version will not be increased. The version may be increased
293             for any reason, and there is no promise that patches will be accepted to
294             lower the minimum required perl.
295              
296             =head1 METHODS
297              
298             =head2 new
299              
300             my $license = $subclass->new(\%arg);
301              
302             This method returns a new license object for the given license class. Valid
303             arguments are:
304              
305             =over 4
306              
307             =item holder
308              
309             the holder of the copyright; required
310              
311             =item year
312              
313             the year of copyright; defaults to current year
314              
315             =item program
316              
317             the name of software for use in the middle of a sentence
318              
319             =item Program
320              
321             the name of software for use in the beginning of a sentence
322              
323             =back
324              
325             C and C arguments may be specified both, either one or none.
326             Each argument, if not specified, is defaulted to another one, or to properly
327             capitalized "this program", if both arguments are omitted.
328              
329             =head2 year
330              
331             =head2 holder
332              
333             These methods are attribute readers.
334              
335             =head2 program
336              
337             Name of software for using in the middle of a sentence.
338              
339             The method returns value of C constructor argument (if it evaluates as true, i. e.
340             defined, non-empty, non-zero), or value of C constructor argument (if it is true), or
341             "this program" as the last resort.
342              
343             =head2 Program
344              
345             Name of software for using in the middle of a sentence.
346              
347             The method returns value of C constructor argument (if it is true), or value of C
348             constructor argument (if it is true), or "This program" as the last resort.
349              
350             =head2 name
351              
352             This method returns the name of the license, suitable for shoving in the middle
353             of a sentence, generally with a leading capitalized "The."
354              
355             =head2 url
356              
357             This method returns the URL at which a canonical text of the license can be
358             found, if one is available. If possible, this will point at plain text, but it
359             may point to an HTML resource.
360              
361             =head2 notice
362              
363             This method returns a snippet of text, usually a few lines, indicating the
364             copyright holder and year of copyright, as well as an indication of the license
365             under which the software is distributed.
366              
367             =head2 license
368              
369             This method returns the full text of the license.
370              
371             =head2 fulltext
372              
373             This method returns the complete text of the license, preceded by the copyright
374             notice.
375              
376             =head2 version
377              
378             This method returns the version of the license. If the license is not
379             versioned, this method will return false.
380              
381             =head2 meta_name
382              
383             This method returns the string that should be used for this license in the CPAN
384             META.yml file, according to the CPAN Meta spec v1, or undef if there is no
385             known string to use.
386              
387             This method may also be invoked as C for legacy reasons.
388              
389             =head2 meta2_name
390              
391             This method returns the string that should be used for this license in the CPAN
392             META.json or META.yml file, according to the CPAN Meta spec v2, or undef if
393             there is no known string to use. If this method does not exist, and
394             C returns open_source, restricted, unrestricted, or unknown, that
395             value will be used.
396              
397             =head2 spdx_expression
398              
399             This method should return the string with the spdx identifier as indicated by
400             L
401              
402             =head1 LOOKING UP LICENSE CLASSES
403              
404             If you have an entry in a F or F file, or similar
405             metadata, and want to look up the Software::License class to use, there are
406             useful tools in L.
407              
408             =head1 TODO
409              
410             =over 4
411              
412             =item *
413              
414             register licenses with aliases to allow $registry->get('gpl', 2);
415              
416             =back
417              
418             =head1 SEE ALSO
419              
420             The specific license:
421              
422             =over 4
423              
424             =item *
425              
426             L
427              
428             =item *
429              
430             L
431              
432             =item *
433              
434             L
435              
436             =item *
437              
438             L
439              
440             =item *
441              
442             L
443              
444             =item *
445              
446             L
447              
448             =item *
449              
450             L
451              
452             =item *
453              
454             L
455              
456             =item *
457              
458             L
459              
460             =item *
461              
462             L
463              
464             =item *
465              
466             L
467              
468             =item *
469              
470             L
471              
472             =item *
473              
474             L
475              
476             =item *
477              
478             L
479              
480             =item *
481              
482             L
483              
484             =item *
485              
486             L
487              
488             =item *
489              
490             L
491              
492             =item *
493              
494             L
495              
496             =item *
497              
498             L
499              
500             =item *
501              
502             L
503              
504             =item *
505              
506             L
507              
508             =item *
509              
510             L
511              
512             =item *
513              
514             L
515              
516             =item *
517              
518             L
519              
520             =item *
521              
522             L
523              
524             =item *
525              
526             L
527              
528             =item *
529              
530             L
531              
532             =item *
533              
534             L
535              
536             =item *
537              
538             L
539              
540             =item *
541              
542             L
543              
544             =item *
545              
546             L
547              
548             =back
549              
550             Extra licenses are maintained on CPAN in separate modules.
551              
552             The L module comes with a script
553             L,
554             which provides a command-line interface
555             to Software::License.
556              
557             =head1 AUTHOR
558              
559             Ricardo Signes
560              
561             =head1 CONTRIBUTORS
562              
563             =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 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ř Shlomi Fish srchulo Syohei YOSHIDA Tomasz Konojacki Van de Bugger Wesley Schwengle
564              
565             =over 4
566              
567             =item *
568              
569             Alex Kapranoff
570              
571             =item *
572              
573             Andrew Grangaard
574              
575             =item *
576              
577             Axel Beckert
578              
579             =item *
580              
581             Bernardo Rechea
582              
583             =item *
584              
585             Bernhard Amann
586              
587             =item *
588              
589             bowtie
590              
591             =item *
592              
593             Brian Cassidy
594              
595             =item *
596              
597             Brian Phillips
598              
599             =item *
600              
601             Craig Scrivner
602              
603             =item *
604              
605             Curtis Brandt
606              
607             =item *
608              
609             Dave Rolsky
610              
611             =item *
612              
613             David E. Wheeler
614              
615             =item *
616              
617             David Golden
618              
619             =item *
620              
621             Dominique Dumont
622              
623             =item *
624              
625             Dylan William Hardison
626              
627             =item *
628              
629             Flavio Poletti
630              
631             =item *
632              
633             Florian Ragwitz
634              
635             =item *
636              
637             Graham Knop
638              
639             =item *
640              
641             Justin Baker
642              
643             =item *
644              
645             Kang-min Liu
646              
647             =item *
648              
649             Karen Etheridge
650              
651             =item *
652              
653             Kenichi Ishigaki
654              
655             =item *
656              
657             Kivanc Yazan
658              
659             =item *
660              
661             Leon Timmermans
662              
663             =item *
664              
665             magnolia
666              
667             =item *
668              
669             Marcel Telka
670              
671             =item *
672              
673             mikegrb
674              
675             =item *
676              
677             Neil Bowers
678              
679             =item *
680              
681             Nicolas Rochelemagne
682              
683             =item *
684              
685             Olivier Mengué
686              
687             =item *
688              
689             Pablo Rodríguez González
690              
691             =item *
692              
693             Petr Písař
694              
695             =item *
696              
697             Shlomi Fish
698              
699             =item *
700              
701             srchulo
702              
703             =item *
704              
705             Syohei YOSHIDA
706              
707             =item *
708              
709             Tomasz Konojacki
710              
711             =item *
712              
713             Van de Bugger
714              
715             =item *
716              
717             Wesley Schwengle
718              
719             =back
720              
721             =head1 COPYRIGHT AND LICENSE
722              
723             This software is copyright (c) 2023 by Ricardo Signes.
724              
725             This is free software; you can redistribute it and/or modify it under
726             the same terms as the Perl 5 programming language system itself.
727              
728             =cut
729              
730             __DATA__