Chart/Plotly/Plot.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 75.0% 15 / 20 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 87.1% 88 / 101 CC 13 SCAR 12.9
CC
13
Cov
88%
html
6.6
from_json
4.0
to_json_text
3.1
CRAP 3.6
« Chart/Plotly/Image.pm ↑ Summary Chart/Plotly/Image/Orca/Client.pm »
1 package Chart::Plotly::Plot;
2  
3 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use JSON qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use UUID::Tiny ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our $VERSION = '0.042'; # VERSION
10  
11 5 ▶use Chart::Plotly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 has traces => ( traits => ['Array'],
14 is => 'rw',
15 isa => 'ArrayRef',
16 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 5 handles => { add_trace => 'push',
18 get_trace => 'get',
19 insert_trace => 'insert',
20 delete_trace => 'delete'
21 }
22 );
23  
24 5 has layout => ( is => 'rw',
25 isa => 'HashRef' );
26  
27 5 has config => ( is => 'rw',
28 isa => 'HashRef' );
29  
30 1 ▶sub html {
Subroutine html: called CC=6 SCAR=18.8
Pod documented
31 1 my $self = shift;
32 1 my %params = @_;
33 1 ▶ my $chart_id = $params{'div_id'} // create_uuid_as_string(UUID_TIME);
Condition33%1/3
$params{"div_id"} // create_uuid_as_string(1)
l!l&&r!l&&!r
010
MC/DC0%0/2
$params{"div_id"} // create_uuid_as_string(1)
$params{"div_id"} create_uuid_as_string(1)
Truth table33%1/3
A // B
A= $params{"div_id"}B= create_uuid_as_string(1)
ABresult
1X1
011
000
34 1 ▶ my $load_plotly_using_script_tag = $params{'load_plotly_using_script_tag'} // 1;
Condition50%1/2
$params{"load_plotly_using_script_tag"} // 1
l!l
01
MC/DC0%0/1
$params{"load_plotly_using_script_tag"} // 1
$params{"load_plotly_using_script_tag"}
Truth table50%1/2
A
A= $params{"load_plotly_using_script_tag"}
Aresult
11
00
35 1 my $layout = $self->layout;
36 1 my $config = $self->config;
37 1 ▶ if ( defined $config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 1 0 1
38 1 $config = Chart::Plotly::_process_data($config);
39 1 ▶ if ( !defined $layout ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $layout) 1 0 1
40 1 $layout = {};
41 }
42 }
43 1 ▶ if ( defined $layout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout) 1 0 1
44 1 $layout = Chart::Plotly::_process_data($layout);
45 }
46 return
47 1 Chart::Plotly::_render_cell( Chart::Plotly::_process_data( $self->traces() ),
48 $chart_id, $layout, $config,
49 { load_plotly_using_script_tag => $load_plotly_using_script_tag } );
50 }
51  
52 5 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=3 SCAR=11.0
Pod documented
53 5 my $self = shift;
54 5 my $layout = $self->layout;
55 5 my $config = $self->config;
56 5 my %json = ( data => $self->traces() );
57 5 ▶ if ( defined $layout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout) 2 3 5
58 2 $json{layout} = $layout;
59 }
60 5 ▶ if ( defined $config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 2 3 5
61 2 $json{config} = $config;
62 }
63 5 return \%json;
64 }
65  
66 2 ▶sub to_json_text {
Subroutine to_json_text: called CC=3 SCAR=11.2
Pod documented
67 2 my $self = shift;
68 2 my $layout = $self->layout;
69 2 my $config = $self->config;
70 2 my $json = '{ "data": ' . Chart::Plotly::_process_data( $self->traces() );
71 2 ▶ if ( defined $layout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout) 0 2 2
72 0 $layout = Chart::Plotly::_process_data($layout);
73 0 $json .= ', "layout": ' . $layout;
74 }
75 2 ▶ if ( defined $config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 1 1 2
76 1 $config = Chart::Plotly::_process_data($config);
77 1 $json .= ', "config": ' . $config;
78 }
79 2 return $json . " }";
80 }
81  
82 3 ▶sub from_json {
Subroutine from_json: called CC=4 SCAR=13.9
Pod documented
83 3 my $class = shift;
84 3 my $json = shift;
85 3 my %data = %{ JSON::from_json($json) };
86 return
87 $class->new( ( defined $data{"data"} ? ( traces => $data{"data"} ) : () ),
88 ( defined $data{"layout"} ? ( layout => $data{"layout"} ) : () ),
89 3 ▶ ( defined $data{"config"} ? ( config => $data{"config"} ) : () )
Branch: 3 branches
BranchTrueFalseTotal
defined $data{'data'} ? : 3 0 3
defined $data{'layout'} ? : 2 1 3
defined $data{'config'} ? : 2 1 3
90 );
91 }
92  
93 5 1;
94  
95 __END__
« Chart/Plotly/Image.pm ↑ Summary Chart/Plotly/Image/Orca/Client.pm »