| 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 | 1 | ▶ | sub derive { | ||||||||
|
Subroutine
derive: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 21 | 1 | my ($self, $args) = @_; | |||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | return unless ref($args) eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 27 | } | ||||||||||
| 28 | 1 | return $new; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 22 | ▶ | sub equal_to { | ||||||||
|
Subroutine
equal_to: called CC=13 SCAR=27.0
Pod
documented
| |||||||||||
| 32 | 22 | my ($self, $other) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 22 | ▶ | return 0 unless defined($other); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 22 | ▶ | unless($self->width == $other->width) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | return 0; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 21 | ▶ | unless($self->line_cap eq $other->line_cap) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | return 0; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 21 | ▶ | unless($self->line_join eq $other->line_join) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | return 0; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 21 | ▶ | if(defined($self->color)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 13 | ▶ | unless($self->color->equal_to($other->color)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 2 | return 0; | |||||||||
| 51 | } | ||||||||||
| 52 | } else { | ||||||||||
| 53 | 8 | ▶ | if(defined($other->color)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return 0; | |||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 19 | ▶ | if(defined($self->dash_pattern)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 2 | ▶ | unless(scalar(@{ $self->dash_pattern }) == scalar(@{ $other->dash_pattern })) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return 0; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | for(my $i = 0; $i < scalar(@{ $self->dash_pattern }); $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 6 | ▶ | unless($self->dash_pattern->[$i] == $other->dash_pattern->[$i]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 1 | return 0; | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | } else { | ||||||||||
| 69 | 17 | ▶ | if(defined($other->dash_pattern)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | return 0; | |||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 18 | return 1; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | ▶ | sub not_equal_to { | ||||||||
|
Subroutine
not_equal_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 78 | 2 | my ($self, $other) = @_; | |||||||||
| 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__ | ||||||||||