line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alien::Plotly::Kaleido; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Finds or installs plotly kaleido |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
226126
|
use 5.010; |
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use parent 'Alien::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
4539
|
use File::Which qw(which); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
14
|
1
|
|
|
1
|
|
752
|
use IPC::Run (); |
|
1
|
|
|
|
|
25795
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
535
|
use JSON (); |
|
1
|
|
|
|
|
8336
|
|
|
1
|
|
|
|
|
26
|
|
16
|
1
|
|
|
1
|
|
7
|
use Path::Tiny (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
322
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub bin_dir { |
19
|
3
|
|
|
3
|
1
|
34701
|
my ($class) = @_; |
20
|
3
|
50
|
|
|
|
12
|
if ( $class->install_type eq 'system' ) { |
21
|
0
|
|
|
|
|
0
|
return Alien::Base::bin_dir($class); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
3
|
|
|
|
|
80
|
return Path::Tiny->new( $class->dist_dir ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub version { |
29
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
30
|
0
|
0
|
|
|
|
0
|
if ( $self->install_type eq 'system' ) { |
31
|
0
|
|
|
|
|
0
|
state $version; |
32
|
0
|
0
|
|
|
|
0
|
unless ($version) { |
33
|
0
|
|
|
|
|
0
|
$version = $self->detect_kaleido_version; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
return $version; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
0
|
|
|
|
|
0
|
return $self->SUPER::version; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub detect_kaleido_version { |
43
|
1
|
|
|
1
|
0
|
267
|
my ($class) = @_; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
6
|
my $kaleido = which('kaleido'); |
46
|
1
|
50
|
|
|
|
118
|
if ($kaleido) { |
47
|
|
|
|
|
|
|
my $decode_json_safe = sub { |
48
|
5
|
|
|
5
|
|
49
|
my ($out) = @_; |
49
|
5
|
|
|
|
|
14
|
my $data; |
50
|
5
|
|
|
|
|
12
|
eval { $data = JSON::decode_json($out); }; |
|
5
|
|
|
|
|
95
|
|
51
|
5
|
100
|
|
|
|
27
|
$@ = '' if ($@); |
52
|
5
|
|
|
|
|
37
|
return $data; |
53
|
1
|
|
|
|
|
8
|
}; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
5
|
my @cmd = ( $kaleido, 'plotly', '--disable-gpu', '--no-sandbox' ); |
56
|
1
|
|
|
|
|
2
|
eval { |
57
|
1
|
|
|
|
|
196
|
require Chart::Plotly; |
58
|
0
|
|
|
|
|
0
|
my $plotlyjs = |
59
|
|
|
|
|
|
|
File::ShareDir::dist_file( 'Chart-Plotly', |
60
|
|
|
|
|
|
|
'plotly.js/plotly.min.js' ); |
61
|
0
|
0
|
|
|
|
0
|
if ( -r $plotlyjs ) { |
62
|
0
|
|
|
|
|
0
|
push @cmd, "--plotlyjs=$plotlyjs"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
}; |
65
|
1
|
|
|
|
|
5
|
my $h; |
66
|
|
|
|
|
|
|
my $data; |
67
|
1
|
|
|
|
|
21
|
eval { |
68
|
1
|
|
|
|
|
5
|
my ( $in, $out, $err ); |
69
|
1
|
|
|
|
|
8
|
$h = IPC::Run::start( \@cmd, \$in, \$out, \$err, |
70
|
|
|
|
|
|
|
my $t = IPC::Run::timer(30) ); |
71
|
1
|
|
66
|
|
|
7390
|
while ( not $data and not $t->is_expired ) { |
72
|
5
|
|
|
|
|
293
|
$h->pump; |
73
|
5
|
|
|
|
|
959512
|
$data = $decode_json_safe->($out); |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
13
|
$h->finish; |
76
|
|
|
|
|
|
|
}; |
77
|
1
|
50
|
|
|
|
40080
|
if ($@) { |
78
|
0
|
|
|
|
|
0
|
warn $@; |
79
|
0
|
|
|
|
|
0
|
$h->kill_kill; |
80
|
|
|
|
|
|
|
} |
81
|
1
|
50
|
33
|
|
|
22
|
if ( $data and exists $data->{version} ) { |
82
|
1
|
|
|
|
|
20
|
return $data->{version}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
die "Failed to detect kaleido version"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |