blib/lib/Graphics/Primitive/Brush.pm

filter: Statementstmt 91.3% 53 / 58 Branchbran 71.4% 20 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 86.6% 84 / 97 SCAR 28.3
CC
16
Cov
85%
equal_to
14.9
derive
4.1
BEGIN
1.0
CRAP 16.9
« blib/lib/Graphics/Primitive/ComponentList.pm ↑ Summary blib/lib/Graphics/Primitive/Component.pm »
1 package Graphics::Primitive::Brush;
2 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use MooseX::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 with 'MooseX::Clone';
7 11 with Storage (format => 'JSON', io => 'File');
8  
9 11 enum 'LineCap' => [qw(butt round square)];
10 11 enum 'LineJoin' => [qw(miter round bevel)];
11  
12 11 has 'color' => ( is => 'rw', isa => 'Graphics::Color', traits => [qw(Clone)] );
13 11 has 'dash_pattern' => ( is => 'rw', isa => 'ArrayRef' );
14 100 ▶has 'width' => ( is => 'rw', isa => 'Int', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 11 has 'line_cap' => ( is => 'rw', isa => 'LineCap', default => 'butt' );
16 11 has 'line_join' => ( is => 'rw', isa => 'LineJoin', default => 'miter' );
17  
18 11 __PACKAGE__->meta->make_immutable;
19  
20 sub derive {
21 1 ▶ my ($self, $args) = @_;
Subroutine derive: called CC=4 SCAR=14.1
Pod documented
22  
23 1 ▶ return unless ref($args) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 1 1
24 1 my $new = $self->clone;
25 1 foreach my $key (keys %{ $args }) {
26 1 ▶ $new->$key($args->{$key}) if($new->can($key));
Branch: 1 branch
BranchTrueFalseTotal
if $new->can($key) 1 0 1
27 }
28 1 return $new;
29 }
30  
31 sub equal_to {
32 22 ▶ my ($self, $other) = @_;
Subroutine equal_to: called CC=13 SCAR=27.0
Pod documented
33  
34 22 ▶ return 0 unless defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 22 22
35  
36 22 ▶ unless($self->width == $other->width) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->width == $other->width) 1 21 22
37 1 return 0;
38 }
39  
40 21 ▶ unless($self->line_cap eq $other->line_cap) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->line_cap eq $other->line_cap) 0 21 21
41 0 return 0;
42 }
43  
44 21 ▶ unless($self->line_join eq $other->line_join) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->line_join eq $other->line_join) 0 21 21
45 0 return 0;
46 }
47  
48 21 ▶ if(defined($self->color)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->color) { } 13 8 21
49 13 ▶ unless($self->color->equal_to($other->color)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->color->equal_to($other->color)) 2 11 13
50 2 return 0;
51 }
52 } else {
53 8 ▶ if(defined($other->color)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $other->color) 0 8 8
54 0 return 0;
55 }
56 }
57  
58 19 ▶ if(defined($self->dash_pattern)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->dash_pattern) { } 2 17 19
59 2 ▶ unless(scalar(@{ $self->dash_pattern }) == scalar(@{ $other->dash_pattern })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$self->dash_pattern;} == scalar @{$other->dash_pattern;}) 0 2 2
60 0 return 0;
61 }
62  
63 2 ▶ for(my $i = 0; $i < scalar(@{ $self->dash_pattern }); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->dash_pattern;}) 6 1 7
64 6 ▶ unless($self->dash_pattern->[$i] == $other->dash_pattern->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dash_pattern->[$i] == $other->dash_pattern->[$i]) 1 5 6
65 1 return 0;
66 }
67 }
68 } else {
69 17 ▶ if(defined($other->dash_pattern)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $other->dash_pattern) 0 17 17
70 0 return 0;
71 }
72 }
73  
74 18 return 1;
75 }
76  
77 sub not_equal_to {
78 2 ▶ my ($self, $other) = @_;
Subroutine not_equal_to: called CC=1 SCAR=0.0
Pod documented
79  
80 2 return !$self->equal_to($other);
81 }
82  
83 11 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 11 1;
85 __END__
86  
87 =head1 NAME
88  
89 Graphics::Primitive::Brush - Description of a stroke
90  
91 =head1 DESCRIPTION
92  
93 Graphics::Primitive::Brush represents the visible trace of 'ink' along a
94 path.
95  
96 =head1 SYNOPSIS
97  
98 use Graphics::Primitive::Brush;
99  
100 my $stroke = Graphics::Primitive::Brush->new({
101 line_cap => 'round',
102 line_join => 'miter',
103 width => 2
104 });
105  
106 =head1 METHODS
107  
108 =head2 Constructor
109  
110 =over 4
111  
112 =item I<new>
113  
114 Creates a new Graphics::Primitive::Brush. Defaults to a width of 1,
115 a line_cap 'butt' and a line_join of 'miter'.
116  
117 =back
118  
119 =head2 Instance Methods
120  
121 =over 4
122  
123 =item I<color>
124  
125 Set/Get this brush's color.
126  
127 =item I<dash_pattern>
128  
129 Set/Get the dash pattern. A dash pattern is an arrayref of numbers
130 representing the lengths of the various line segments of the dash. Even
131 numbered elements are considered opaque and odd elements are transparent.
132  
133 =item I<derive>
134  
135 Clone this brush but change one or more of it's attributes by passing in a
136 hashref of options:
137  
138 my $new = $brush->derive({ attr => $newvalue });
139
140 The returned font will be identical to the cloned one, save the attributes
141 specified.
142  
143 =item I<equal_to ($other)>
144  
145 Returns 1 if this brush is equal to the supplied one, else returns 0.
146  
147 =item I<line_cap>
148  
149 Set/Get the line_cap of this stroke. Valid values are butt, round and square.
150  
151 =item I<line_join>
152  
153 Set/Get the line_join of this stroke. Valid values are miter, round and bevel.
154  
155 =item I<not_equal_to ($other)>
156  
157 Opposite of equal_to.
158  
159 =item I<width>
160  
161 Set/Get the width of this stroke. Defaults to 1
162  
163 =back
164  
165 =head1 AUTHOR
166  
167 Cory Watson, C<< <gphat@cpan.org> >>
168  
169 =head1 COPYRIGHT & LICENSE
170  
171 Copyright 2008-2010 by Cory G Watson.
172  
173 This program is free software; you can redistribute it and/or modify it
174 under the same terms as Perl itself.
« blib/lib/Graphics/Primitive/ComponentList.pm ↑ Summary blib/lib/Graphics/Primitive/Component.pm »