Chart/WithMarker.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 88 CC 1 SCAR 6.9
CC
1
Cov
0%
add_marker
2.0
_build_markers
2.0
add_marker
2.0
CRAP 2.0
1 package Google::Chart::WithMarker;
2 use Moose::Role;
3 use namespace::clean -except => qw(meta);
4  
5 with 'Google::Chart::WithData';
6  
7 around _build_dataset_traits => sub {
8 my ($next, $self) = @_;
9  
10 my $traits = $next->($self);
11 push @$traits, 'Google::Chart::DataSet::WithMarker';
12 return $traits;
13 };
14  
15 around prepare_query => sub {
16 my ($next, $self, @args) = @_;
17  
18 my @query = $next->($self, @args);
19  
20 my $datasets = $self->get_datasets;
21 my $max = $#$datasets;
22 my @chm;
23 for my $i (0..$max) {
24 my $dataset = $datasets->[$i];
25  
26 if ( $dataset->has_markers ) {
27 my $markers = $dataset->markers;
28 foreach my $marker (@$markers) {
29 push @chm, join(',',
30 $marker->type,
31 $marker->color || '',
32 $i,
33 !defined $marker->point ? -1 : $marker->point,
34 $marker->size || '',
35 $marker->priority || ''
36 );
37 }
38 }
39 }
40  
41 if (@chm) {
42 push @query, ( chm => join('|', @chm) );
43 }
44  
45 return @query;
46 };
47  
48 sub add_marker {
49 my ($self, %args) = @_;
50  
51 my $dataset_index = delete $args{dataset_index} || 0;
52 my $dataset = $self->data->get_dataset_at($dataset_index) or
53 confess "dataset at index $dataset_index does NOT exist!";
54  
55 $dataset->add_marker(%args);
56 }
57  
58 package # hide from PAUSE
59 Google::Chart::DataSet::WithMarker;
60 use Moose::Role;
61 use namespace::clean -except => qw(meta);
62  
63 has markers => (
64 is => 'ro',
65 isa => 'ArrayRef[Google::Chart::Marker]',
66 lazy_build => 1,
67 predicate => 'has_markers',
68 );
69  
70 sub _build_markers { [] }
71  
72 sub add_marker {
73 my ($self, %args) = @_;
74  
75 my $marker = Google::Chart::Marker->new(%args);
76 push @{ $self->markers }, $marker;
77 }
78  
79 package # hide from PAUSE
80 Google::Chart::Marker;
81 use Moose;
82 use Moose::Util::TypeConstraints qw(subtype as where);
83 subtype 'Google::Chart::DataSet::MarkerType'
84 => as 'Str'
85 => where {
86 /^(?:[acdosvVhx]|t[^,]+)/
87 }
88 ;
89  
90 has type => (
91 is => 'ro',
92 isa => 'Google::Chart::DataSet::MarkerType',
93 );
94  
95 has color => (
96 is => 'ro',
97 isa => 'Str',
98 );
99  
100 has size => (
101 is => 'ro',
102 isa => 'Num',
103 );
104  
105 has point => (
106 is => 'ro',
107 isa => 'Num',
108 );
109  
110 has priority => (
111 is => 'ro',
112 isa => 'Num',
113 );
114  
115 __PACKAGE__->meta->make_immutable();
116  
117 1;