File Coverage

blib/lib/App/cpanm/meta/checker/State.pm
Criterion Covered Total %
statement 36 80 45.0
branch 0 12 0.0
condition n/a
subroutine 12 23 52.1
pod 5 5 100.0
total 53 120 44.1


line stmt bran cond sub pod time code
1 2     2   1476 use 5.008; # utf8
  2         7  
  2         87  
2 2     2   13 use strict;
  2         5  
  2         80  
3 2     2   11 use warnings;
  2         4  
  2         68  
4 2     2   900 use utf8;
  2         12  
  2         18  
5              
6             package App::cpanm::meta::checker::State;
7             $App::cpanm::meta::checker::State::VERSION = '0.001001';
8             # ABSTRACT: Shared state for a single test run
9              
10             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11              
12 2     2   971 use Moo qw(has);
  2         16833  
  2         13  
13 2     2   1910 use Carp qw(croak);
  2         3  
  2         112  
14 2     2   2621 use CPAN::Meta;
  2         78210  
  2         74  
15 2     2   2290 use CPAN::Meta::Check qw(verify_dependencies);
  2         46015  
  2         164  
16 2     2   1542 use App::cpanm::meta::checker::State::Duplicates;
  2         10  
  2         83  
17 2     2   1163 use Path::Tiny qw(path);
  2         13112  
  2         2432  
18              
19              
20              
21              
22              
23             has 'tests' => (
24             is => ro =>,
25             lazy => 1,
26             required => 1,
27             );
28              
29              
30              
31              
32              
33             has 'list_fd' => (
34             is => ro =>,
35             lazy => 1,
36             builder => sub {
37 0     0     \*STDERR;
38             },
39             );
40              
41             has '_duplicates' => (
42             is => ro =>,
43             lazy => 1,
44             builder => sub {
45 0     0     return App::cpanm::meta::checker::State::Duplicates->new();
46             },
47             );
48              
49             sub _output {
50 0     0     my ( $self, $prefix, $message ) = @_;
51 0           return $self->list_fd->printf( qq[%s: %s\n], $prefix, $message );
52             }
53              
54              
55              
56              
57              
58             sub x_test_list {
59 0     0 1   my ( $self, $path, ) = @_;
60 0           return $self->_output( 'list', path($path)->basename );
61             }
62              
63              
64              
65              
66              
67             sub x_test_list_nonempty {
68 0     0 1   my ( $self, $path ) = @_;
69 0 0         return unless path($path)->children;
70 0           return $self->_output( 'list_nonempty', path($path)->basename );
71             }
72              
73              
74              
75              
76              
77             sub x_test_list_empty {
78 0     0 1   my ( $self, $path ) = @_;
79 0 0         return if path($path)->children;
80 0           return $self->_output( 'list_empty', path($path)->basename );
81             }
82              
83             ## no critic (Compatibility::PerlMinimumVersionAndWhy)
84             # _Pulp__5010_qr_m_propagate_properly
85             my $distversion_re = qr{
86             \A
87             (.*)
88             -
89             (
90             [^-]+
91             (?:-TRIAL)?
92             )
93             \z
94             }msx;
95              
96              
97              
98              
99              
100             sub x_test_list_duplicates {
101 0     0 1   my ( $self, $path ) = @_;
102 0           my $basename = path($path)->basename;
103 0           my ( $dist, $version ) = $basename =~ $distversion_re;
104 0           $self->_duplicates->seen_dist_version( $dist, $version );
105              
106 0 0         return unless $self->_duplicates->has_duplicates($dist);
107              
108 0           my $label = 'list_duplicates';
109 0           my $fmt = '%s-%s';
110              
111 0 0         if ( $self->_duplicates->reported_duplicates($dist) ) {
112 0           $self->_output( $label, sprintf $fmt, $dist, $version );
113 0           return;
114             }
115              
116 0           $self->_output( $label, sprintf $fmt, $dist, $_ ) for $self->_duplicates->duplicate_versions($dist);
117              
118 0           $self->_duplicates->reported_duplicates( $dist, 1 );
119              
120 0           return;
121             }
122              
123             sub _cache_cpan_meta {
124 0     0     my ( undef, $path, $state ) = @_;
125 0 0         return $state->{cpan_meta} if defined $state->{cpan_meta};
126 0           return ( $state->{cpan_meta} = CPAN::Meta->load_file( path($path)->child('MYMETA.json') ) );
127             }
128              
129             sub _cpan_meta_check_phase_type {
130 0     0     my ( $self, %args ) = @_;
131 0           my $meta = $self->_cache_cpan_meta( $args{path}, $args{state} );
132 0           for my $dep ( verify_dependencies( $meta, $args{phase}, $args{type} ) ) {
133 0           $self->_output( $args{label}, ( sprintf '%s: %s', path( $args{path} )->basename, $dep ) );
134             }
135 0           return;
136             }
137              
138              
139              
140              
141              
142              
143              
144              
145              
146              
147              
148              
149              
150              
151              
152              
153              
154              
155              
156              
157              
158              
159              
160              
161              
162              
163              
164              
165              
166              
167              
168              
169              
170              
171              
172              
173              
174              
175              
176              
177              
178              
179              
180             for my $phase (qw( runtime configure build develop test )) {
181             for my $rel (qw( requires suggests conflicts recommends )) {
182             my $method = 'x_test_check_' . $phase . '_' . $rel;
183              
184             my $code = sub {
185 0     0     my ( $self, $path, $state ) = @_;
186 0           return $self->_cpan_meta_check_phase_type(
187             path => $path,
188             state => $state,
189             label => ( 'check_' . $phase . '_' . $rel ),
190             phase => $phase,
191             type => $rel,
192             );
193             };
194             {
195             ## no critic (TestingAndDebugging::ProhibitNoStrict)
196 2     2   18 no strict 'refs';
  2         6  
  2         395  
197             *{$method} = $code;
198             }
199             }
200             }
201              
202              
203              
204              
205              
206              
207              
208              
209              
210             sub check_path {
211 0     0 1   my ( $self, $path ) = @_;
212 0           my $state = {};
213 0           for my $test ( @{ $self->tests } ) {
  0            
214 0           my $method = 'x_test_' . $test;
215 0 0         if ( not $self->can($method) ) {
216 0           return croak("no method $method for test $test");
217             }
218 0           $self->$method( $path, $state );
219             }
220 0           return;
221             }
222              
223 2     2   11 no Moo;
  2         3  
  2         16  
224              
225             1;
226              
227             __END__