| 1 | package Chart::OFC::Types; | ||||||||||||||||||||||||||||
| 2 | 41 | $Chart::OFC::Types::VERSION = '0.12'; | |||||||||||||||||||||||||||
| 3 | 41 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 41 | ▶ | use Graphics::ColorNames; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 41 | ▶ | use List::MoreUtils qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 41 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | subtype 'Chart::OFC::Type::Color' | ||||||||||||||||||||||||||||
| 11 | => as 'Str', | ||||||||||||||||||||||||||||
| 12 | 239 | ▶ | => where { ( uc $_ ) =~ /^\#[0-9A-F]{6}$/ } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | => message { "$_ is not a valid six-digit hex color" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 41 | coerce 'Chart::OFC::Type::Color' | |||||||||||||||||||||||||||
| 16 | => from 'Str' | ||||||||||||||||||||||||||||
| 17 | => via \&_name_to_hex_color; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||
| 20 | 41 | my $names = Graphics::ColorNames->new(); | |||||||||||||||||||||||||||
| 21 | sub _name_to_hex_color | ||||||||||||||||||||||||||||
| 22 | 56 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_name_to_hex_color: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 41 | ▶ | no warnings 'uninitialized'; ## no critic ProhibitNoWarnings | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 56 | return uc $names->hex( $_, '#' ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 41 | subtype 'Chart::OFC::Type::NonEmptyArrayRef' | |||||||||||||||||||||||||||
| 29 | => as 'ArrayRef' | ||||||||||||||||||||||||||||
| 30 | 103 | ▶ | => where { return scalar @{ $_ } > 0 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 41 | my $constraint = find_type_constraint('Num'); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNums' | ||||||||||||||||||||||||||||
| 36 | => as 'Chart::OFC::Type::NonEmptyArrayRef', | ||||||||||||||||||||||||||||
| 37 | 24 | ▶ | => where { return 0 if any { ! $constraint->check($_) } @{ $_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 23 | return 1; } | |||||||||||||||||||||||||||
| 39 | 2 | ▶ | => message { 'array reference must contain only numbers and cannot be empty' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs' | ||||||||||||||||||||||||||||
| 42 | => as 'Chart::OFC::Type::NonEmptyArrayRef', | ||||||||||||||||||||||||||||
| 43 | 35 | ▶ | => where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 35 | return 1; } | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | => message { 'array reference cannot be empty and must contain numbers or undef' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 41 | my $constraint = find_type_constraint('Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs'); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | subtype 'Chart::OFC::Type::NonEmptyArrayRefOfArrayRefsOfNumsOrUndefs' | ||||||||||||||||||||||||||||
| 52 | => as 'Chart::OFC::Type::NonEmptyArrayRef', | ||||||||||||||||||||||||||||
| 53 | 13 | ▶ | => where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 54 | 12 | return 1; } | |||||||||||||||||||||||||||
| 55 | 2 | ▶ | => message { 'array reference cannot be empty and must contain more array references of numbers or undef' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 41 | my $constraint = find_type_constraint('Chart::OFC::Type::Color'); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | subtype 'Chart::OFC::Type::NonEmptyArrayRefOfColors' | ||||||||||||||||||||||||||||
| 62 | => as 'Chart::OFC::Type::NonEmptyArrayRef', | ||||||||||||||||||||||||||||
| 63 | 6 | ▶ | => where { return 0 unless @{ $_ } > 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | return 0 if any { ! $constraint->check($_) } @{ $_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 2 | return 1; } | |||||||||||||||||||||||||||
| 66 | 2 | ▶ | => message { 'array reference cannot be empty and must be a list of colors' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | coerce 'Chart::OFC::Type::NonEmptyArrayRefOfColors' | ||||||||||||||||||||||||||||
| 69 | => from 'ArrayRef' | ||||||||||||||||||||||||||||
| 70 | 4 | ▶ | => via { [ map { $constraint->coerce($_) } @{ $_ } ] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 41 | ▶ | my $constraint = find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset'); | ||||||||||||||||||||||||||
|
Condition66%2/3
find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset')
MC/DC0%0/2
find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset')
find_type_constraint('Chart::OFC::Dataset')
class_type('Chart::OFC::Dataset')
Truth table66%2/3
A || B
A= find_type_constraint('Chart::OFC::Dataset')B= class_type('Chart::OFC::Dataset')
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | subtype 'Chart::OFC::Type::NonEmptyArrayRefOfTypedDatasets' | ||||||||||||||||||||||||||||
| 77 | => as 'Chart::OFC::Type::NonEmptyArrayRef', | ||||||||||||||||||||||||||||
| 78 | 11 | ▶ | => where { return 0 unless @{ $_ } > 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 11 | ▶ | return 0 if any { ! ( $constraint->check($_) && $_->can('type') ) } @{ $_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.9
Branch: 1 branch
Condition33%1/3
$constraint->check($_) && $_->can('type')
MC/DC0%0/2
$constraint->check($_) && $_->can('type')
$constraint->check($_)
$_->can('type')
Truth table33%1/3
A && B
A= $constraint->check($_)B= $_->can('type')
| |||||||||||||||||||||||||||||
| 80 | 11 | return 1; } | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | => message { 'array reference cannot be must be a list of typed datasets' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 41 | ▶ | unless ( find_type_constraint('Chart::OFC::AxisLabel' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | subtype 'Chart::OFC::AxisLabel' | ||||||||||||||||||||||||||||
| 87 | => as 'Object' | ||||||||||||||||||||||||||||
| 88 | 16 | ▶ | => where { $_->isa('Chart::OFC::AxisLabel') }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | coerce 'Chart::OFC::AxisLabel' | ||||||||||||||||||||||||||||
| 92 | => from 'HashRef' | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | => via { Chart::OFC::AxisLabel->new( %{ $_ } ) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | => from 'Str' | ||||||||||||||||||||||||||||
| 95 | 9 | ▶ | => via { Chart::OFC::AxisLabel->new( label => $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | subtype 'Chart::OFC::Type::Angle' | ||||||||||||||||||||||||||||
| 98 | => as 'Int' | ||||||||||||||||||||||||||||
| 99 | 4 | ▶ | => where { $_ >= 0 && $_ <= 359 } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | => message { "$_ is not a number from 0-359" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | subtype 'Chart::OFC::Type::Opacity' | ||||||||||||||||||||||||||||
| 103 | => as 'Int' | ||||||||||||||||||||||||||||
| 104 | 35 | ▶ | => where { $_ >= 0 && $_ <= 100 } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | => message { "$_ is not a number from 0-100" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | subtype 'Chart::OFC::Type::PosInt' | ||||||||||||||||||||||||||||
| 108 | => as 'Int' | ||||||||||||||||||||||||||||
| 109 | 118 | ▶ | => where { $_ > 0 } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | => message { 'must be a positive integer' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | subtype 'Chart::OFC::Type::PosOrZeroInt' | ||||||||||||||||||||||||||||
| 113 | => as 'Int' | ||||||||||||||||||||||||||||
| 114 | 3 | ▶ | => where { $_ >= 0 } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | => message { 'must be an integer greater than or equal to zero' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 41 | subtype 'Chart::OFC::Type::Size' | |||||||||||||||||||||||||||
| 118 | => as 'Chart::OFC::Type::PosInt'; | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 41 | 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 | 41 | ▶ | no warnings 'redefine'; ## no critic ProhibitNoWarnings | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 56 | ▶ | sub hex { ## no critic ProhibitBuiltinHomonyms | ||||||||||||||||||||||||||
|
Subroutine
hex: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 56 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | 56 | my $name = shift; | |||||||||||||||||||||||||||
| 133 | 56 | my $rgb = $self->FETCH($name); | |||||||||||||||||||||||||||
| 134 | 56 | ▶ | return unless defined $rgb; # this is the monkey line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 55 | my $pre = shift; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | unless (defined $pre) { $pre = ""; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 55 | return ($pre.$rgb); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 41 | ▶ | no Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 41 | 1; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # ABSTRACT: type library for Chart::OFC | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||