blib/lib/Data/Faker/Colour.pm

filter: Statementstmt 81.2% 52 / 64 Branchbran 78.5% 11 / 14 Conditioncond 100% 10 / 10 MC/DCmcdc 100% 5 / 5 Subroutinesub 62.5% 10 / 16 Podpod 70.0% 7 / 10 totaltotal 79.8% 95 / 119 CC 17 SCAR 18.7
CC
17
Cov
83%
colour_hsluv
13.0
colour
4.0
to_hex
2.0
CRAP 6.5
↑ Summary
1 package Data::Faker::Colour;
2  
3 1 ▶use 5.014000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use parent qw/Data::Faker/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Convert::Color::HSLuv;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.001';
10  
11 1 ▶sub new { bless {}, shift } # Don't call superclass constructor
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12  
13 18 ▶sub ir ($) { int rand $_[0] }
Subroutine ir: called CC=1 SCAR=0.0
Pod undocumented
14  
15 2 ▶sub colour {
Subroutine colour: called CC=4 SCAR=13.9
Pod documented
16 2 shift; # drop $self
17 2 ▶ my $cnt = shift // 1;
Condition100%2/2
shift() // 1
l!l
11
MC/DC100%1/1
shift() // 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 2 my %args = @_;
19 2 my @ret;
20  
21 2 for (1 .. $cnt) {
22 6 push @ret, [ir 256, ir 256, ir 256]
23 }
24  
25 2 ▶ wantarray ? @ret : $ret[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
26 }
27  
28 5 ▶sub colour_hsluv {
Subroutine colour_hsluv: called CC=13 SCAR=25.7
Pod documented
29 5 shift; # drop $self
30 5 my @ret;
31 5 my ($cnt, $ch, $cs, $cl) = @_;
32 5 ▶ $cnt //= 1;
Condition100%2/2
$cnt //= 1
l!l
41
MC/DC100%1/1
$cnt //= 1
$cnt
Truth table100%2/2
A
A= $cnt
Aresult
11
00
33 5 ▶ $ch //= -1;
Condition100%2/2
$ch //= -1
l!l
41
MC/DC100%1/1
$ch //= -1
$ch
Truth table100%2/2
A
A= $ch
Aresult
11
00
34 5 ▶ $cs //= -1;
Condition100%2/2
$cs //= -1
l!l
32
MC/DC100%1/1
$cs //= -1
$cs
Truth table100%2/2
A
A= $cs
Aresult
11
00
35 5 ▶ $cl //= -1;
Condition100%2/2
$cl //= -1
l!l
23
MC/DC100%1/1
$cl //= -1
$cl
Truth table100%2/2
A
A= $cl
Aresult
11
00
36  
37 5 for (1 .. $cnt) {
38 2601 my ($h, $s, $l) = ($ch, $cs, $cl);
39 2601 ▶ $h = rand 360 if $h < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $h < 0 2401 200 2601
40 2601 ▶ $s = rand 100 if $s < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s < 0 401 2200 2601
41 2601 ▶ $l = rand 100 if $l < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $l < 0 401 2200 2601
42 2601 my @colour = Convert::Color::HSLuv->new($h, $s, $l)->rgb;
43 2601 for (@colour) {
44 7803 $_ = int (256 * $_);
45 7803 ▶ $_ = 0 if $_ < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 0 0 7803 7803
46 7803 ▶ $_ = 255 if $_ > 255;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > 255 7 7796 7803
47 }
48 2601 push @ret, \@colour
49 }
50  
51 5 ▶ wantarray ? @ret : $ret[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
52 }
53  
54 0 ▶sub to_hex {
Subroutine to_hex: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my ($rgb) = @_;
56 0 sprintf "#%02x%02x%02x", @$rgb
57 }
58  
59 0 ▶sub to_css {
Subroutine to_css: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ($rgb) = @_;
61 0 sprintf 'rgb(%d,%d,%d)', @$rgb
62 }
63  
64 0 ▶sub colour_hex { map { to_hex $_ } colour @_ }
Subroutine colour_hex: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub colour_css { map { to_css $_ } colour @_ }
Subroutine colour_css: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub colour_hsluv_hex { map { to_hex $_ } colour_hsluv @_ }
Subroutine colour_hsluv_hex: not called CC=1 SCAR=6.9
Pod documented
67 0 ▶sub colour_hsluv_css { map { to_css $_ } colour_hsluv @_ }
Subroutine colour_hsluv_css: not called CC=1 SCAR=6.9
Pod documented
68  
69 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
70 1 *color = *colour;
71 1 *color_hsluv = *colour_hsluv;
72 1 *color_hex = *colour_hex;
73 1 *color_hsluv_hex = *colour_hsluv_hex;
74 1 *color_css = *colour_css;
75 1 *color_hsluv_css = *colour_hsluv_css;
76  
77 1 for my $c (qw/colour color/) {
78 2 __PACKAGE__->register_plugin(
79 "${c}" => \&colour,
80 "${c}_hsluv" => \&colour_hsluv,
81 "${c}_hex" => \&colour_hex,
82 "${c}_hsluv_hex" => \&colour_hsluv_hex,
83 "${c}_css" => \&colour_css,
84 "${c}_hsluv_css" => \&colour_hsluv_css,
85 );
86 }
87 }
88  
89 1 1;
90 __END__
↑ Summary