Chart/Plotly/Image.pm

filter: Statementstmt 85.2% 58 / 68 Branchbran 57.1% 8 / 14 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 12 / 14 Podpod 100% 1 / 1 totaltotal 76.1% 80 / 105 CC 11 SCAR 14.7
CC
11
Cov
77%
save_image
8.9
_save_image_kaleido
4.8
_save_image_orca
2.0
CRAP 4.4
« Chart/Plotly/Trace/Scatter.pm ↑ Summary Chart/Plotly/Plot.pm »
1 package Chart::Plotly::Image;
2  
3 # ABSTRACT: Export static images of Plotly charts
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.042'; # VERSION
11  
12 1 ▶use Chart::Plotly::Image::Orca;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Chart::Plotly::Image::Orca::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @EXPORT_OK = qw(save_image);
17  
18 2 ▶sub save_image {
Subroutine save_image: called CC=8 SCAR=21.9
Pod documented
19 2 my %params = @_;
20 2 ▶ my $engine = ( delete $params{engine} ) || 'auto';
Condition50%1/2
delete $params{'engine'} || 'auto'
l!l
20
MC/DC0%0/1
delete $params{'engine'} || 'auto'
delete $params{'engine'}
Truth table50%1/2
A
A= delete $params{'engine'}
Aresult
11
00
21  
22 2 my @supported_engines = qw(kaleido orca);
23 2 ▶ unless ( grep { $_ eq $engine } ( 'auto', @supported_engines ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $engine;} "auto", @supported_engines) 0 2 2
24 0 die "Unsupported engine: $engine";
25 }
26  
27 2 ▶ if ( $params{orca_server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"orca_server"}) 0 2 2
28 0 _save_image_orca_client(%params);
29 }
30  
31 2 ▶ if ( $engine eq 'auto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($engine eq "auto") 1 1 2
32 1 for my $candidate (qw(kaleido orca)) {
33 1 my $func_has = "_has_$candidate";
34 1 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶ if ( $func_has->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$func_has()) 1 0 1
36 1 $engine = $candidate;
37 1 last;
38 }
39 }
40 }
41 2 ▶ if ( $engine eq 'auto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($engine eq "auto") 0 2 2
42 0 die "None of @{[join(', ', @supported_engines)]} are available. "
43 . "Please install Chart::Kaleido::Plotly (recommended) or Alien::Plotly::Orca. ";
44 }
45 2 my $func_save = "_save_image_$engine";
46 1 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 return $func_save->(%params);
48 }
49  
50 4 ▶sub _has_kaleido {
Subroutine _has_kaleido: called CC=1 SCAR=0.0
51 4 eval {
52 4 require Chart::Kaleido::Plotly;
53 4 Chart::Kaleido::Plotly->VERSION(0.005);
54 };
55 4 return !$@;
56 }
57  
58 1 ▶sub _has_orca {
Subroutine _has_orca: called CC=1 SCAR=0.0
59 1 my $has_orca;
60 1 eval { $has_orca = Chart::Plotly::Image::Orca::orca_available };
61 1 return $has_orca;
62 }
63  
64 2 ▶sub _save_image_kaleido {
Subroutine _save_image_kaleido: called CC=4 SCAR=15.8
65 2 my %params = @_;
66  
67 2 _has_kaleido();
68  
69 # Chart::Kaleido::Plotly's interface uses plotlyjs not plotly
70 2 ▶ if ( my $plotlyjs_via_plotly_param = delete $params{plotly} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $plotlyjs_via_plotly_param = delete $params{"plotly"}) 0 2 2
71 0 ▶ $params{plotlyjs} ||= $plotlyjs_via_plotly_param;
Condition0%0/3
$params{"plotlyjs"} ||= $plotlyjs_via_plotly_param
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{"plotlyjs"} ||= $plotlyjs_via_plotly_param
$params{"plotlyjs"} $plotlyjs_via_plotly_param
Truth table0%0/3
A ||= B
A= $params{"plotlyjs"}B= $plotlyjs_via_plotly_param
ABresult
1X1
011
000
72 }
73 my %kaleido_params =
74 2 ▶ map { exists $params{$_} ? ( $_ => delete $params{$_} ) : () } @{ Chart::Kaleido::Plotly->scope_flags };
Branch: 1 branch
BranchTrueFalseTotal
exists $params{$_} ? : 0 8 8
75 2 my $kaleido = Chart::Kaleido::Plotly->new(%kaleido_params);
76 2 $kaleido->save(%params);
77 }
78  
79 0 ▶sub _save_image_orca {
Subroutine _save_image_orca: not called CC=1 SCAR=6.9
80 0 my %params = @_;
81  
82 0 Chart::Plotly::Image::Orca::orca(%params);
83 }
84  
85 0 ▶sub _save_image_orca_client {
Subroutine _save_image_orca_client: not called CC=1 SCAR=6.9
86 0 my %params = @_;
87  
88 0 $params{server} = delete $params{orca_server};
89 0 Chart::Plotly::Image::Orca::Client::save_image(%params);
90 }
91  
92 1 1;
93  
94 __END__
« Chart/Plotly/Trace/Scatter.pm ↑ Summary Chart/Plotly/Plot.pm »