File Coverage

blib/lib/App/Midgen/Role/FindMinVersion.pm
Criterion Covered Total %
statement 27 56 48.2
branch 0 18 0.0
condition n/a
subroutine 9 15 60.0
pod 1 1 100.0
total 37 90 41.1


line stmt bran cond sub pod time code
1             package App::Midgen::Role::FindMinVersion;
2              
3 2     2   1006 use constant { ONE => 1, TWO => 2, TRUE => 1, FALSE => 0,};
  2         4  
  2         237  
4              
5 2     2   10 use Types::Standard qw( Bool );
  2         2  
  2         16  
6 2     2   740 use Moo::Role;
  2         3  
  2         13  
7             requires qw( ppi_document debug experimental verbose );
8              
9             our $VERSION = '0.33_05';
10             $VERSION = eval $VERSION; ## no critic
11              
12 2     2   4691 use Perl::MinimumVersion;
  2         232829  
  2         118  
13 2     2   22 use Try::Tiny;
  2         3  
  2         117  
14 2     2   8 use Term::ANSIColor qw( :constants colored colorstrip );
  2         3  
  2         602  
15 2     2   10 use version;
  2         2  
  2         14  
16 2     2   138 use Data::Printer {caller_info => 1,};
  2         3  
  2         22  
17              
18             has 'mro_skip' => (
19             is => 'rwp',
20             isa => Bool,
21             lazy => 1,
22             default => sub { 0; },
23             );
24              
25              
26             #######
27             # find min perl version - pmv
28             ######
29             sub min_version {
30 0     0 1   my $self = shift;
31 0           my $filename = shift;
32 0           $filename =~ s{^/}{};
33              
34 0           my $dist_min_ver = $App::Midgen::Min_Version;
35 0           my $object;
36              
37             try {
38 0     0     $object = Perl::MinimumVersion->new($self->ppi_document);
39 0           };
40              
41             # Find the minimum version
42             try {
43 0 0   0     $dist_min_ver
44             = version->parse($dist_min_ver)
45             > version->parse($object->minimum_version)
46             ? version->parse($dist_min_ver)
47             : version->parse($object->minimum_version);
48 0           };
49              
50             try {
51 0 0   0     $dist_min_ver
52             = version->parse($dist_min_ver)
53             > version->parse($object->minimum_explicit_version)
54             ? version->parse($dist_min_ver)
55             : version->parse($object->minimum_explicit_version);
56 0           };
57              
58             try {
59 0 0   0     $dist_min_ver
60             = version->parse($dist_min_ver)
61             > version->parse($object->minimum_syntax_version)
62             ? version->parse($dist_min_ver)
63             : version->parse($object->minimum_syntax_version);
64 0           };
65              
66             try {
67 0     0     my $blame = $object->minimum_syntax_reason->element->content;
68              
69 0 0         if ($blame =~ m/\bmro[\s|;]/) {
70 0           $self->_set_mro_skip(TRUE);
71 0 0         print BRIGHT_BLACK
72             . 'Info: PMV blame = '
73             . $blame
74             . ' -> 5.010 in '
75             . $filename
76             . CLEAR . "\n" if ($self->verbose >= ONE);
77             }
78 0           };
79              
80 0 0         if ($self->mro_skip) {
81 0 0         if (defined $self->{modules}{'MRO::Compat'}) {
82 0           foreach my $index (0 .. $#{$self->{modules}{'MRO::Compat'}{infiles}}) {
  0            
83 0 0         if ($self->{modules}{'MRO::Compat'}{infiles}->[$index][0] eq '/'
84             . $filename)
85             {
86 0           print BRIGHT_BLACK
87             . 'Warning: '
88             . WHITE . 'mro'
89             . BRIGHT_BLACK . ' & '
90             . WHITE
91             . 'MRO::Compat'
92             . BRIGHT_BLACK
93             . ' in the same module ^^, hence skipping pmv.'
94             . CLEAR . "\n";
95 0           $self->_set_mro_skip(FALSE);
96 0           return;
97             }
98             }
99             }
100             }
101             else {
102 0 0         print "min_version - $dist_min_ver\n" if ($self->{verbose} == TWO);
103 0           $App::Midgen::Min_Version = version->parse($dist_min_ver)->numify;
104             }
105              
106 0           return;
107             }
108              
109 2     2   2561 no Moo::Role;
  2         4  
  2         19  
110              
111             1;
112              
113              
114             __END__
115              
116             =pod
117              
118             =encoding UTF-8
119              
120             =head1 NAME
121              
122             App::Midgen::Roles::FindMinVersion - used by L<App::Midgen>
123              
124             =head1 VERSION
125              
126             version: 0.33_05
127              
128             =head1 METHODS
129              
130             =over 4
131              
132             =item * min_version
133              
134             Used to find the minimum version of your package by taking a quick look,
135             in a module or script and updating C<$App::Midgen::Min_Version> accordingly.
136              
137             =back
138              
139             =head1 AUTHOR
140              
141             See L<App::Midgen>
142              
143             =head2 CONTRIBUTORS
144              
145             See L<App::Midgen>
146              
147             =head1 COPYRIGHT
148              
149             See L<App::Midgen>
150              
151             =head1 LICENSE
152              
153             This library is free software; you can redistribute it and/or modify
154             it under the same terms as Perl itself.
155              
156             =cut
157