File Coverage

blib/lib/App/cpanmigrate.pm
Criterion Covered Total %
statement 6 29 20.6
branch 0 6 0.0
condition 0 3 0.0
subroutine 2 7 28.5
pod 0 5 0.0
total 8 50 16.0


line stmt bran cond sub pod time code
1             package App::cpanmigrate;
2 1     1   6 use strict;
  1         1  
  1         42  
3 1     1   5 use warnings;
  1         2  
  1         568  
4             our $VERSION = '0.04';
5              
6             local $SIG{__DIE__} = sub {
7             my $msg = shift;
8             warn "$msg\n";
9             exit 1;
10             };
11              
12             sub new {
13 0     0 0   my ($class, $new_version, %args) = @_;
14              
15 0 0 0       ($new_version && $new_version =~ /^perl/)
16             or __PACKAGE__->usage();
17              
18 0           return bless {
19             args => { %args },
20             version => $new_version,
21             }, $class;
22             }
23              
24             sub run {
25 0     0 0   my $self = shift;
26              
27 0           $self->detect_shell;
28 0           my $command = $self->fetch_script;
29              
30 0           exec $self->{shell}{path}, @{$self->{shell}{opts}}, $command;
  0            
31             }
32              
33             sub fetch_script {
34 0     0 0   my $self = shift;
35 0           my $shell = $self->{shell};
36              
37 0           require "App/cpanmigrate/$shell->{name}.pm"; ## no critic
38              
39 0           my $cmd = "App::cpanmigrate::$shell->{name}"->script($self->{version});
40 0           $cmd =~ s/\s+/ /g;
41              
42 0           return $cmd;
43             }
44              
45             sub usage {
46 0     0 0   die <<"USAGE";
47             Usage:
48             $0 [perl-version]
49             USAGE
50             }
51              
52             sub detect_shell {
53 0     0 0   my $self = shift;
54              
55 0           $self->{shell}{path} = $ENV{SHELL};
56              
57 0 0         if ($self->{shell}{path} =~ /(bash|zsh)/) {
    0          
58 0           $self->{shell}{name} = 'bash';
59 0           $self->{shell}{opts} = [ '-c' ];
60              
61             } elsif ($self->{shell}{path} =~ /(csh)/) {
62 0           $self->{shell}{name} = 'csh';
63 0           $self->{shell}{opts} = [ '-c' ];
64              
65             } else {
66 0           $self->{shell}{name} = 'unknown';
67             }
68             }
69              
70             1;
71             __END__