File Coverage

blib/lib/DMOSS/Plugin/VerifyLicense.pm
Criterion Covered Total %
statement 18 39 46.1
branch 0 12 0.0
condition n/a
subroutine 6 12 50.0
pod 6 6 100.0
total 30 69 43.4


line stmt bran cond sub pod time code
1             package DMOSS::Plugin::VerifyLicense;
2             $DMOSS::Plugin::VerifyLicense::VERSION = '0.01_2';
3             # ABSTRACT: DMOSS fix me description
4 1     1   7 use parent qw/DMOSS::Plugin/;
  1         2  
  1         9  
5              
6 1     1   70 use strict;
  1         1  
  1         33  
7 1     1   4 use warnings;
  1         2  
  1         30  
8              
9 1     1   808 use Software::License;
  1         42892  
  1         41  
10 1     1   935 use Software::LicenseUtils;
  1         187804  
  1         52  
11 1     1   11 use File::Slurp qw/read_file/;
  1         3  
  1         808  
12              
13             our @types = qw/README LICENSE/;
14              
15 0     0 1   sub name { 'Verify License' }
16              
17             sub process {
18 0     0 1   my ($self, $dmoss, $file) = @_;
19 0           my $content = read_file $file->fullpath;
20 0 0         return unless $content =~ m/\b(licen[cs]e|licensing|copyright|legal)\b/;
21              
22             # guess license
23 0           $content = "=head1 license\n" . $content . "\n=cut";
24 0           my @guesses = Software::LicenseUtils->guess_license_from_pod($content);
25 0           my $top = shift @guesses;
26              
27 0 0         if ($top) {
28 0           my $license = $top->name;
29 0           $dmoss->add_attr('license', $license);
30             }
31             }
32              
33             sub reduce {
34 0     0 1   my ($self, $dmoss, @attrs) = @_;
35 0 0         return unless @attrs;
36              
37 0 0         if (@attrs > 1) { # more than one license was found
38             # FIXME
39             }
40             else {
41 0           $dmoss->add_attr('license', $attrs[0]->value);
42             }
43             }
44              
45             sub report {
46 0     0 1   my ($self, $dmoss, $attr) = @_;
47              
48 0           return [ $attr->file->{path}, $attr->value ];
49             }
50              
51             sub report_headers {
52 0     0 1   my ($self, $dmoss) = @_;
53              
54 0           return [ 'File', 'License' ];
55             }
56              
57             sub grade {
58 0     0 1   my ($self, $dmoss, $attr) = @_;
59 0 0         return 0 unless $attr;
60              
61 0 0         return ( $attr->value ? 1 : 0 );
62             }
63              
64             1;
65              
66             __END__