| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # This file is part of Software-LicenseMoreUtils | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # This software is copyright (c) 2018, 2022 by Dominique Dumont. | 
| 5 |  |  |  |  |  |  | # | 
| 6 |  |  |  |  |  |  | # This is free software; you can redistribute it and/or modify it under | 
| 7 |  |  |  |  |  |  | # the same terms as the Perl 5 programming language system itself. | 
| 8 |  |  |  |  |  |  | # | 
| 9 |  |  |  |  |  |  | package Software::LicenseMoreUtils::LicenseWithSummary; | 
| 10 |  |  |  |  |  |  | $Software::LicenseMoreUtils::LicenseWithSummary::VERSION = '1.007'; | 
| 11 |  |  |  |  |  |  | # ABSTRACT: Software::License with a summary | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 3 |  |  | 3 |  | 16 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 84 |  | 
| 14 | 3 |  |  | 3 |  | 13 | use warnings; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 53 |  | 
| 15 | 3 |  |  | 3 |  | 23 | use 5.10.1; | 
|  | 3 |  |  |  |  | 9 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 3 |  |  | 3 |  | 1191 | use Path::Tiny; | 
|  | 3 |  |  |  |  | 18178 |  | 
|  | 3 |  |  |  |  | 147 |  | 
| 18 | 3 |  |  | 3 |  | 1409 | use YAML::Tiny; | 
|  | 3 |  |  |  |  | 12956 |  | 
|  | 3 |  |  |  |  | 157 |  | 
| 19 | 3 |  |  | 3 |  | 26 | use List::Util qw/first/; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 223 |  | 
| 20 | 3 |  |  | 3 |  | 17 | use Carp; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 112 |  | 
| 21 | 3 |  |  | 3 |  | 1844 | use Text::Template; | 
|  | 3 |  |  |  |  | 8410 |  | 
|  | 3 |  |  |  |  | 1448 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | our $AUTOLOAD; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # map location of distro file (like /etc/redhat_release) to distro. | 
| 26 |  |  |  |  |  |  | # must match a _summaries.yml file in the directory containing | 
| 27 |  |  |  |  |  |  | # this Perl module file | 
| 28 |  |  |  |  |  |  | my %path_to_distro = ( | 
| 29 |  |  |  |  |  |  | '/etc/debian_version' => 'debian', | 
| 30 |  |  |  |  |  |  | ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | my $distro_file = first { -e $_ } keys %path_to_distro; | 
| 33 |  |  |  |  |  |  | my $distro = $path_to_distro{$distro_file // ''} || 'unknown'; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | (my $module_file = __PACKAGE__.'.pm' ) =~ s!::!/!g; | 
| 36 |  |  |  |  |  |  | my $yml_file = path($INC{$module_file})->parent->child("$distro-summaries.yml") ; | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | my $summaries = {} ; | 
| 39 |  |  |  |  |  |  | if ($yml_file->is_file) { | 
| 40 |  |  |  |  |  |  | $summaries = YAML::Tiny->read($yml_file)->[0]; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub new { | 
| 44 | 22 |  |  | 22 | 0 | 41 | my ($class, $args) = @_; | 
| 45 |  |  |  |  |  |  | my $self = { | 
| 46 |  |  |  |  |  |  | license => $args->{license}, | 
| 47 |  |  |  |  |  |  | or_later => $args->{or_later}, | 
| 48 | 22 |  |  |  |  | 54 | }; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 22 |  |  |  |  | 44 | return bless $self, $class; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 20 |  |  | 20 | 1 | 5531 | sub distribution { return $distro } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub summary { | 
| 56 | 25 |  |  | 25 | 1 | 52707 | my $self = shift; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 25 | 100 |  |  |  | 63 | my $later_text = $self->{or_later} ? ", or (at\nyour option) any later version" : ''; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 25 |  |  |  |  | 119 | (my $section_name = ref( $self->{license} )) =~ s/.*:://; | 
| 61 | 25 |  | 100 |  |  | 78 | my $summary = $summaries->{$section_name} // ''; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 25 |  |  |  |  | 100 | my $template = Text::Template->new( | 
| 64 |  |  |  |  |  |  | TYPE => 'STRING', | 
| 65 |  |  |  |  |  |  | DELIMITERS => [ qw({{ }}) ], | 
| 66 |  |  |  |  |  |  | SOURCE => $summary | 
| 67 |  |  |  |  |  |  | ); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 25 |  |  |  |  | 2327 | return $template->fill_in( | 
| 70 |  |  |  |  |  |  | HASH => { or_later_clause => $later_text }, | 
| 71 |  |  |  |  |  |  | ); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub license_class { | 
| 75 | 6 |  |  | 6 | 1 | 20 | my $self = shift; | 
| 76 | 6 |  |  |  |  | 21 | return ref($self->{license}); | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub debian_text { | 
| 80 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 81 | 0 |  |  |  |  | 0 | carp "debian_text is deprecated, please use summary_or_text"; | 
| 82 | 0 |  |  |  |  | 0 | return $self->summary_or_text; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub summary_or_text { | 
| 86 | 11 |  |  | 11 | 1 | 19419 | my $self = shift; | 
| 87 | 11 | 100 |  |  |  | 19 | return join("\n",  grep { $_ } ($self->notice, $self->summary)) | 
|  | 14 |  |  |  |  | 2397 |  | 
| 88 |  |  |  |  |  |  | if length $self->summary; | 
| 89 | 4 |  |  |  |  | 840 | return $self->fulltext; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 93 | 34 |  |  | 34 |  | 29431 | my ($self, @args) = @_; | 
| 94 | 34 |  |  |  |  | 59 | my $lic = $self->{license}; | 
| 95 | 34 |  |  |  |  | 230 | my ($sub) = ($AUTOLOAD =~ /(\w+)$/); | 
| 96 | 34 | 100 | 66 |  |  | 187 | if ($lic and $sub ne 'DESTROY') { | 
| 97 | 12 |  |  |  |  | 53 | return $lic->$sub(@args); | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  | else { | 
| 100 | 22 |  |  |  |  | 248 | return; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | 1; | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | __END__ |