blib/lib/Convert/Color/IRC.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 81.8% 36 / 44 CC 6 SCAR 15.2
CC
6
Cov
83%
new
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
↑ Summary
1 package Convert::Color::IRC;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base qw( Convert::Color::RGB8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use constant COLOR_SPACE => 'irc';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.06';
11  
12 =head1 NAME
13  
14 C<Convert::Color::IRC> - named lookup for the basic IRC colors
15  
16 =head1 SYNOPSIS
17  
18 Directly:
19  
20 use Convert::Color::IRC;
21  
22 my $red = Convert::Color::IRC->new( 'red' );
23  
24 # Can also use index
25 my $black = Convert::Color::IRC->new( 1 );
26  
27 Via L<Convert::Color>:
28  
29 use Convert::Color;
30  
31 my $cyan = Convert::Color->new( 'irc:cyan' );
32  
33 =head1 DESCRIPTION
34  
35 This subclass of L<Convert::Color::RG8B> provides predefined colors for the 16
36 basic IRC colors. Their names are
37  
38 white
39 black
40 blue
41 green
42 red
43 brown
44 purple
45 orange
46 yellow
47 light green
48 cyan
49 light cyan
50 light blue
51 pink
52 gray
53 light gray
54  
55 They may be looked up either by name, or by numerical index within this list.
56  
57 =cut
58  
59 2 my %irc_colors = (
60 white => [ 255, 255, 255 ],
61 black => [ 0, 0, 0 ],
62 blue => [ 0, 0, 255 ],
63 green => [ 0, 255, 0 ],
64 red => [ 255, 0, 0 ],
65 brown => [ 165, 42, 42 ],
66 purple => [ 128, 0, 128 ],
67 orange => [ 255, 165, 0 ],
68 yellow => [ 255, 255, 0 ],
69 'light green' => [ 144, 238, 144 ],
70 cyan => [ 0, 255, 255 ],
71 'light cyan' => [ 224, 255, 255 ],
72 'light blue' => [ 173, 216, 230 ],
73 pink => [ 255, 192, 203 ],
74 gray => [ 128, 128, 128 ],
75 'light gray' => [ 211, 211, 211 ]
76 );
77  
78 # Also indexes
79 2 my @irc_colors = (
80 'white', 'black', 'blue', 'green',
81 'red', 'brown', 'purple', 'orange',
82 'yellow', 'light green', 'cyan', 'light cyan',
83 'light blue', 'pink', 'gray', 'light gray'
84 );
85  
86 =head1 CONSTRUCTOR
87  
88 =cut
89  
90 =head2 $color = Convert::Color::IRC->new( $name )
91  
92 Returns a new object to represent the named color.
93  
94 =head2 $color = Convert::Color::IRC->new( $index )
95  
96 Returns a new object to represent the color at the given index.
97  
98 =cut
99  
100 sub new
101 9 ▶{
Subroutine new: called CC=6 SCAR=19.4
Pod documented
102 9 my $class = shift;
103 9 my $name = shift;
104
105 9 ▶ if( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 9 0 9
106 9 ▶ if( $name =~ m/^\d{1,2}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\d{1,2}$/) 3 6 9
107 3 ▶ $name >= 0 and $name < @irc_colors or
Branch: 1 branch
BranchTrueFalseTotal
$name >= 0 and $name < @irc_colors or croak("No such IRC color at index $name") 3 0 3
Condition33%1/3
$name >= 0 and $name < @irc_colors
!ll&&!rl&&r
003
MC/DC0%0/2
$name >= 0 and $name < @irc_colors
$name >= 0 $name < @irc_colors
Truth table33%1/3
A and B
A= $name >= 0B= $name < @irc_colors
ABresult
0X0
100
111
108 croak "No such IRC color at index $name";
109  
110 3 $name = $irc_colors[$name];
111 }
112 9 ▶ my $color = $irc_colors{$name} or
Branch: 1 branch
BranchTrueFalseTotal
my $color = $irc_colors{$name} or croak("No such IRC color named '${name}'") 9 0 9
113 croak "No such IRC color named '$name'";
114  
115 9 return $class->SUPER::new( @$color );
116 }
117 else {
118 0 croak "usage: Convert::Color::IRC->new( NAME ) or ->new( INDEX )";
119 }
120 }
121  
122 # Keep perl happy; keep Britain tidy
123 2 1;
124  
125 __END__
↑ Summary