line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chart::OFC::Types; |
2
|
|
|
|
|
|
|
$Chart::OFC::Types::VERSION = '0.12'; |
3
|
20
|
|
|
20
|
|
128
|
use strict; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
760
|
|
4
|
20
|
|
|
20
|
|
119
|
use warnings; |
|
20
|
|
|
|
|
36
|
|
|
20
|
|
|
|
|
608
|
|
5
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
21362
|
use Graphics::ColorNames; |
|
20
|
|
|
|
|
181961
|
|
|
20
|
|
|
|
|
1170
|
|
7
|
20
|
|
|
20
|
|
221
|
use List::MoreUtils qw( any ); |
|
20
|
|
|
|
|
52
|
|
|
20
|
|
|
|
|
1052
|
|
8
|
20
|
|
|
20
|
|
132
|
use Moose::Util::TypeConstraints; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
630
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::Color' |
11
|
|
|
|
|
|
|
=> as 'Str', |
12
|
|
|
|
|
|
|
=> where { ( uc $_ ) =~ /^\#[0-9A-F]{6}$/ } |
13
|
|
|
|
|
|
|
=> message { "$_ is not a valid six-digit hex color" }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
coerce 'Chart::OFC::Type::Color' |
16
|
|
|
|
|
|
|
=> from 'Str' |
17
|
|
|
|
|
|
|
=> via \&_name_to_hex_color; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
my $names = Graphics::ColorNames->new(); |
21
|
|
|
|
|
|
|
sub _name_to_hex_color |
22
|
|
|
|
|
|
|
{ |
23
|
20
|
|
|
20
|
|
44221
|
no warnings 'uninitialized'; ## no critic ProhibitNoWarnings |
|
20
|
|
|
|
|
110
|
|
|
20
|
|
|
|
|
21562
|
|
24
|
56
|
|
|
56
|
|
2987
|
return uc $names->hex( $_, '#' ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRef' |
29
|
|
|
|
|
|
|
=> as 'ArrayRef' |
30
|
|
|
|
|
|
|
=> where { return scalar @{ $_ } > 0 }; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
my $constraint = find_type_constraint('Num'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNums' |
36
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::NonEmptyArrayRef', |
37
|
|
|
|
|
|
|
=> where { return 0 if any { ! $constraint->check($_) } @{ $_ }; |
38
|
|
|
|
|
|
|
return 1; } |
39
|
|
|
|
|
|
|
=> message { 'array reference must contain only numbers and cannot be empty' }; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs' |
42
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::NonEmptyArrayRef', |
43
|
|
|
|
|
|
|
=> where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ }; |
44
|
|
|
|
|
|
|
return 1; } |
45
|
|
|
|
|
|
|
=> message { 'array reference cannot be empty and must contain numbers or undef' }; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
my $constraint = find_type_constraint('Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRefOfArrayRefsOfNumsOrUndefs' |
52
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::NonEmptyArrayRef', |
53
|
|
|
|
|
|
|
=> where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ }; |
54
|
|
|
|
|
|
|
return 1; } |
55
|
|
|
|
|
|
|
=> message { 'array reference cannot be empty and must contain more array references of numbers or undef' }; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
my $constraint = find_type_constraint('Chart::OFC::Type::Color'); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRefOfColors' |
62
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::NonEmptyArrayRef', |
63
|
|
|
|
|
|
|
=> where { return 0 unless @{ $_ } > 0; |
64
|
|
|
|
|
|
|
return 0 if any { ! $constraint->check($_) } @{ $_ }; |
65
|
|
|
|
|
|
|
return 1; } |
66
|
|
|
|
|
|
|
=> message { 'array reference cannot be empty and must be a list of colors' }; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
coerce 'Chart::OFC::Type::NonEmptyArrayRefOfColors' |
69
|
|
|
|
|
|
|
=> from 'ArrayRef' |
70
|
|
|
|
|
|
|
=> via { [ map { $constraint->coerce($_) } @{ $_ } ] }; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
my $constraint = find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset'); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::NonEmptyArrayRefOfTypedDatasets' |
77
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::NonEmptyArrayRef', |
78
|
|
|
|
|
|
|
=> where { return 0 unless @{ $_ } > 0; |
79
|
|
|
|
|
|
|
return 0 if any { ! ( $constraint->check($_) && $_->can('type') ) } @{ $_ }; |
80
|
|
|
|
|
|
|
return 1; } |
81
|
|
|
|
|
|
|
=> message { 'array reference cannot be must be a list of typed datasets' }; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
unless ( find_type_constraint('Chart::OFC::AxisLabel' ) ) |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
subtype 'Chart::OFC::AxisLabel' |
87
|
|
|
|
|
|
|
=> as 'Object' |
88
|
|
|
|
|
|
|
=> where { $_->isa('Chart::OFC::AxisLabel') }; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
coerce 'Chart::OFC::AxisLabel' |
92
|
|
|
|
|
|
|
=> from 'HashRef' |
93
|
|
|
|
|
|
|
=> via { Chart::OFC::AxisLabel->new( %{ $_ } ) } |
94
|
|
|
|
|
|
|
=> from 'Str' |
95
|
|
|
|
|
|
|
=> via { Chart::OFC::AxisLabel->new( label => $_ ) }; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::Angle' |
98
|
|
|
|
|
|
|
=> as 'Int' |
99
|
|
|
|
|
|
|
=> where { $_ >= 0 && $_ <= 359 } |
100
|
|
|
|
|
|
|
=> message { "$_ is not a number from 0-359" }; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::Opacity' |
103
|
|
|
|
|
|
|
=> as 'Int' |
104
|
|
|
|
|
|
|
=> where { $_ >= 0 && $_ <= 100 } |
105
|
|
|
|
|
|
|
=> message { "$_ is not a number from 0-100" }; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::PosInt' |
108
|
|
|
|
|
|
|
=> as 'Int' |
109
|
|
|
|
|
|
|
=> where { $_ > 0 } |
110
|
|
|
|
|
|
|
=> message { 'must be a positive integer' }; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::PosOrZeroInt' |
113
|
|
|
|
|
|
|
=> as 'Int' |
114
|
|
|
|
|
|
|
=> where { $_ >= 0 } |
115
|
|
|
|
|
|
|
=> message { 'must be an integer greater than or equal to zero' }; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
subtype 'Chart::OFC::Type::Size' |
118
|
|
|
|
|
|
|
=> as 'Chart::OFC::Type::PosInt'; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
enum 'Chart::OFC::Type::Orientation' => [qw( horizontal vertical diagonal )]; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
# Monkey-patch to shut up an annoying warning! |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package ## no critic ProhibitMultiplePackages |
127
|
|
|
|
|
|
|
Graphics::ColorNames; |
128
|
|
|
|
|
|
|
|
129
|
20
|
|
|
20
|
|
132
|
no warnings 'redefine'; ## no critic ProhibitNoWarnings |
|
20
|
|
|
|
|
41
|
|
|
20
|
|
|
|
|
2479
|
|
130
|
|
|
|
|
|
|
sub hex { ## no critic ProhibitBuiltinHomonyms |
131
|
56
|
|
|
56
|
1
|
96
|
my $self = shift; |
132
|
56
|
|
|
|
|
110
|
my $name = shift; |
133
|
56
|
|
|
|
|
295
|
my $rgb = $self->FETCH($name); |
134
|
56
|
100
|
|
|
|
1521
|
return unless defined $rgb; # this is the monkey line |
135
|
55
|
|
|
|
|
106
|
my $pre = shift; |
136
|
55
|
50
|
|
|
|
174
|
unless (defined $pre) { $pre = ""; } |
|
0
|
|
|
|
|
0
|
|
137
|
55
|
|
|
|
|
1952
|
return ($pre.$rgb); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
20
|
|
|
20
|
|
139
|
no Moose::Util::TypeConstraints; |
|
20
|
|
|
|
|
42
|
|
|
20
|
|
|
|
|
145
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# ABSTRACT: type library for Chart::OFC |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=pod |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NAME |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Chart::OFC::Types - type library for Chart::OFC |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 VERSION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
version 0.12 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SYNOPSIS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
package Chart::OFC::Thingy; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
use Chart::OFC::Types; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
use Moose; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
has opacity => ( |
169
|
|
|
|
|
|
|
is => 'ro', |
170
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::Opacity', |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 DESCRIPTION |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This class provides a library of types for use by other Chart::OFC |
176
|
|
|
|
|
|
|
classes. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Dave Rolsky. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This is free software, licensed under: |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |