line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSAN::Shell; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Provides the main functionality for the JSAN CLI installer |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
17
|
use base 'Class::Accessor::Fast'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1052
|
|
9
|
1
|
|
|
1
|
|
3958
|
use File::Spec (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
6
|
use File::Path (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
11
|
1
|
|
|
1
|
|
1464
|
use File::Temp (); |
|
1
|
|
|
|
|
24750
|
|
|
1
|
|
|
|
|
28
|
|
12
|
1
|
|
|
1
|
|
76
|
use Cwd; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
73
|
|
13
|
1
|
|
|
1
|
|
575
|
use JSAN::Indexer; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
4
|
|
14
|
1
|
|
|
1
|
|
7
|
use LWP::Simple; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
17
|
|
|
|
|
|
|
our $SHELL; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[_index my_mirror]); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
0
|
|
0
|
1
|
|
return $SHELL if $SHELL; |
23
|
0
|
|
|
|
|
|
my ($class) = shift; |
24
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new({@_}); |
25
|
0
|
0
|
|
|
|
|
$self->my_mirror('http://openjsan.org') unless $self->my_mirror; |
26
|
0
|
|
|
|
|
|
return $SHELL = $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub index { |
30
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
31
|
0
|
0
|
|
|
|
|
return $self->_index if $self->_index; |
32
|
0
|
|
|
|
|
|
$self->_index(JSAN::Indexer->new); |
33
|
0
|
|
|
|
|
|
return $self->_index; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub install { |
37
|
0
|
|
|
0
|
0
|
|
my ($self, $lib, $prefix) = @_; |
38
|
0
|
0
|
|
|
|
|
die "You must supply a prefix to install to" unless $prefix; |
39
|
0
|
|
|
|
|
|
$prefix = File::Spec->rel2abs($prefix); |
40
|
0
|
|
|
|
|
|
File::Path::mkpath($prefix); |
41
|
0
|
|
|
|
|
|
my $library = $self->index->library->retrieve($lib); |
42
|
0
|
0
|
|
|
|
|
die "No such library $lib" unless $library; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
die "$lib is up to date: " . $library->version . "\n" |
45
|
|
|
|
|
|
|
if $self->_check_uptodate($library, $prefix); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $release = $library->release; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $deps = $release->meta->requires; |
50
|
0
|
|
|
|
|
|
foreach my $dep ( @{$deps} ) { |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
eval { $self->install($dep->{name}, $prefix) }; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $link = join '', $self->my_mirror, $release->source; |
55
|
0
|
|
|
|
|
|
my $dir = File::Temp::tempdir(CLEANUP => 0); |
56
|
0
|
|
|
|
|
|
my $file = (split /\//, $link)[-1]; |
57
|
0
|
|
|
|
|
|
print $release->source . " -> $dir/$file\n"; |
58
|
0
|
|
|
|
|
|
my $tarball = LWP::Simple::get($link); |
59
|
0
|
0
|
|
|
|
|
die "Downloading dist [$link] failed." unless $tarball; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $pwd = getcwd(); |
62
|
0
|
|
|
|
|
|
chdir "$dir"; |
63
|
0
|
|
|
|
|
|
print "Unpacking $file\n"; |
64
|
0
|
0
|
|
|
|
|
open DIST, "> $file" or die $!; |
65
|
0
|
|
|
|
|
|
print DIST $tarball; |
66
|
0
|
|
|
|
|
|
close DIST; |
67
|
0
|
|
|
|
|
|
`tar xzvf $file`; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
print "Installing libraries to $prefix\n"; |
70
|
0
|
|
|
|
|
|
chdir $release->srcdir; |
71
|
0
|
|
|
|
|
|
`cp -r lib/* $prefix`; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
chdir $pwd; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub index_create { |
77
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
78
|
0
|
|
|
|
|
|
my $mirror = join '/', $self->my_mirror, 'index.yaml'; |
79
|
0
|
|
|
|
|
|
JSAN::Indexer->create_index_db($mirror); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub index_get { |
83
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
84
|
0
|
|
|
|
|
|
my $rc = LWP::Simple::mirror($self->my_mirror . "/index.sqlite", $JSAN::Indexer::INDEX_DB); |
85
|
0
|
0
|
|
|
|
|
die "Could not mirror index" unless -e $JSAN::Indexer::INDEX_DB; |
86
|
0
|
|
|
|
|
|
print "Downloaded index.\n"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _check_uptodate { |
90
|
0
|
|
|
0
|
|
|
my ($self, $library, $prefix) = @_; |
91
|
0
|
|
|
|
|
|
my $lib = $library->name; |
92
|
0
|
|
|
|
|
|
$lib =~ s[\.][/]g; |
93
|
0
|
|
|
|
|
|
$lib = "$prefix/$lib.js"; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if ( -e $lib ) { |
96
|
0
|
0
|
|
|
|
|
open LIB, $lib or die "Up to date check failed for " . $library->name; |
97
|
0
|
|
|
|
|
|
while () { |
98
|
0
|
|
|
|
|
|
my ($version) = $_ =~ /VERSION\s*(?:=|:)\s*[^\d._]*([\d._]+)/; |
99
|
0
|
0
|
|
|
|
|
next unless $version; |
100
|
0
|
0
|
|
|
|
|
return 1 if $version eq $library->version; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
close LIB; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |