File Coverage

lib/Test/LatestPrereqs/Config.pm
Criterion Covered Total %
statement 21 37 56.7
branch 3 12 25.0
condition 1 8 12.5
subroutine 8 9 88.8
pod 2 2 100.0
total 35 68 51.4


line stmt bran cond sub pod time code
1             package Test::LatestPrereqs::Config;
2            
3 5     5   24 use strict;
  5         11  
  5         311  
4 5     5   27 use warnings;
  5         11  
  5         143  
5 5     5   26 use File::Spec;
  5         9  
  5         193  
6 5     5   24 use CPAN::Version;
  5         7  
  5         2363  
7            
8             our $CONFIG;
9            
10             sub load {
11 3     3 1 8 my $class = shift;
12            
13 3 50       13 unless ($CONFIG) {
14 3 50       22 if (open my $fh, '<', _file()) {
15 0         0 while(<$fh>) {
16 0         0 chomp;
17 0         0 my ($module, $version) = split /\s+/, $_, 2;
18 0   0     0 $CONFIG->{$module} = $version || 0;
19             }
20             }
21            
22 3   33     295 $CONFIG ||= $class->_recommend;
23             }
24            
25 3         16 return $CONFIG;
26             }
27            
28             sub save {
29 0     0 1 0 my ($class, @requires) = @_;
30            
31 0         0 $class->load;
32 0         0 foreach my $require (@requires) {
33 0         0 my ($module, $version) = @{ $require };
  0         0  
34 0 0       0 next unless $version;
35 0 0 0     0 if (!$CONFIG->{$module} or CPAN::Version->vgt($version, $CONFIG->{$module})) {
36 0         0 $CONFIG->{$module} = $version;
37             }
38             }
39 0 0       0 if (open my $fh, '>', _file()) {
40 0         0 foreach my $module (keys %{ $CONFIG }) {
  0         0  
41 0         0 print $fh $module, "\t", $CONFIG->{$module}, "\n";
42             }
43             }
44             }
45            
46             sub _file {
47 3     3   10 File::Spec->catfile(_home(), '.test_prereqs_version');
48             }
49            
50             sub _home {
51 3     3   285 eval "require File::HomeDir";
52 3 50       27539 return $@ ? '.' : File::HomeDir->my_home;
53             }
54            
55             sub _recommend {
56             return {
57             # better error handling
58 3     3   41 'CLI::Dispatch' => '0.03',
59            
60             # better DBD::SQLite support
61             'DBI' => '1.608',
62             'DBD::SQLite' => '1.25',
63            
64             # file_or_die() support
65             'Path::Extended' => '0.12',
66            
67             # for better trap and japanese test messages
68             'Test::Classy' => '0.07',
69            
70             # t/lib support
71             'Test::UseAllModules' => '0.11',
72             };
73             }
74            
75             1;
76            
77             __END__