File Coverage

blib/lib/R/Setup.pm
Criterion Covered Total %
statement 23 73 31.5
branch 0 26 0.0
condition 0 12 0.0
subroutine 8 18 44.4
pod 0 10 0.0
total 31 139 22.3


line stmt bran cond sub pod time code
1             # perl program for R installation
2             #
3             # Copyright (C) 2015, Snehasis Sinha
4             #
5              
6             package R::Setup;
7              
8 1     1   20622 use 5.010001;
  1         5  
9 1     1   6 use strict;
  1         2  
  1         21  
10 1     1   4 use warnings;
  1         2  
  1         27  
11              
12 1     1   579 use R::Setup::Bootstrap;
  1         2  
  1         40  
13 1     1   681 use R::Setup::Resolve;
  1         3  
  1         31  
14 1     1   548 use R::Setup::Download;
  1         3  
  1         35  
15 1     1   581 use R::Setup::Install;
  1         3  
  1         28  
16 1     1   503 use R::Setup::Local;
  1         2  
  1         919  
17              
18             our @ISA = qw();
19             our $VERSION = '0.01';
20              
21              
22             # package methods
23              
24             sub new {
25 0     0 0   my $class = shift;
26 0           my %params = @_;
27             my $self = {
28             bootstrap => $params{'bootstrap'} || undef,
29             resolve => $params{'resolve'} || undef,
30             download => $params{'download'} || undef,
31             install => $params{'install'} || undef,
32             asklist => $params{'packages'},
33             rsource => $params{'rsource'} || 'R-3.1.2.tar.gz',
34             urlbase => $params{'urlbase'}, # only required for local
35             deplist => undef,
36             tarlist => undef,
37             # listfile => $params{'depslistfile'} || 'package.list',
38 0   0       verbose => $params{'verbose'} || 1, # default:yes
      0        
      0        
      0        
      0        
      0        
39             };
40 0           bless $self, $class;
41 0           return $self;
42             }
43              
44             sub download_source {
45 0     0 0   my ($self, %args) = (@_);
46              
47 0 0         $args{'source'} = $self->{'rsource'} unless defined $args{'source'};
48 0 0         $self->{'download'} = R::Setup::Download->new unless defined $self->{'download'};
49 0           $self->{'download'}->download_binary (source=>$args{'source'});
50             }
51              
52             sub set_package_list {
53 0     0 0   my ($self) = (@_);
54              
55             # resolve dependencies
56 0 0         unless (defined $self->{'resolve'}) {
57 0 0         unless (defined $self->{'asklist'}) {
58 0 0         print "no package list supplied. exit!\n" if $self->{'verbose'};
59             }
60            
61 0           $self->{'resolve'} = R::Setup::Resolve->new(packages=>$self->{'asklist'});
62             }
63 0           $self->{'deplist'} = $self->{'resolve'}->resolve;
64 0           $self->save ( whichlist=>'deplist' );
65             }
66              
67             sub download_packages {
68 0     0 0   my ($self) = (@_);
69              
70             # read from default file for consistency
71 0 0         $self->read ( whichlist=>'deplist' ) unless defined $self->{'deplist'};
72              
73             # download deps package in this session
74 0           $self->{'download'} = R::Setup::Download->new ( packages=>$self->{'deplist'} );
75            
76 0           $self->{'download'}->prepare ( refresh=>1 );
77 0           $self->{'tarlist'} = $self->{'download'}->dumplist;
78             # store in file for offline installation
79 0           $self->save ( whichlist=>'tarlist' );
80            
81             # download packages
82 0           $self->{'download'}->download;
83             }
84              
85             sub read {
86 0     0 0   my ($self, %args) = (@_);
87 0           my @t;
88              
89 0 0         open FILE, '<'.$args{'whichlist'} or die $!;
90 0           @t = ;
91 0           close FILE;
92 0           chomp @t;
93              
94 0           $self->{$args{'whichlist'}} = \@t;
95 0 0         print scalar @t." records loaded from ".$args{'whichlist'}."\n" if $self->{'verbose'};
96             }
97              
98             sub save {
99 0     0 0   my ($self, %args) = (@_);
100              
101 0 0         open FILE, '>'.$args{'whichlist'} or die $!;
102 0           foreach ( @{$self->{$args{'whichlist'}}} ) {
  0            
103 0           print FILE $_."\n";
104             }
105 0           close FILE;
106             }
107              
108             sub build_from_source {
109 0     0 0   my ($self) = (@_);
110              
111 0 0         $self->{'bootstrap'} = R::Setup::Bootstrap->new unless defined $self->{'bootstrap'};
112 0           $self->{'bootstrap'}->build;
113             }
114              
115             sub install {
116 0     0 0   my ($self) = (@_);
117              
118 0 0         $self->{'bootstrap'} = R::Setup::Bootstrap->new unless defined $self->{'bootstrap'};
119              
120             # install R with sudo
121 0           $self->{'bootstrap'}->install;
122             }
123              
124             sub install_packages {
125 0     0 0   my ($self) = (@_);
126              
127             # read from default file for consistency
128 0 0         $self->read ( whichlist=>'tarlist' ) unless defined $self->{'tarlist'};
129              
130             $self->{'install'} = R::Setup::Install->new (list=>$self->{'tarlist'})
131 0 0         unless defined $self->{'install'};
132              
133             # install packages with sudo
134 0           $self->{'install'}->install;
135             }
136              
137             sub download_local {
138 0     0 0   my ($self) = (@_);
139              
140 0           my $ldw = R::Setup::Local->new ( urlbase=>$self->{'urlbase'} );
141 0           $ldw->download_local;
142             }
143              
144             1;
145             __END__