| 1 | package TUI::ColorSel::ColorItem; | ||||||||||
| 2 | # ABSTRACT: singly linked color item used by color dialog structures | ||||||||||
| 3 | |||||||||||
| 4 | 8 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 8 | our $VERSION = '2.000002'; | |||||||||
| 9 | 8 | $VERSION =~ tr/_//d; | |||||||||
| 10 | 8 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||
| 11 | |||||||||||
| 12 | 8 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 8 | our @EXPORT = qw( | |||||||||
| 14 | TColorItem | ||||||||||
| 15 | new_TColorItem | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 8 | ▶ | use Devel::StrictMode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 8 | ▶ | use if STRICT => 'Hash::Util'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 8 | ▶ | use TUI::toolkit qw( :utils ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 8 | ▶ | use TUI::toolkit::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | Maybe | ||||||||||
| 23 | is_Object | ||||||||||
| 24 | :types | ||||||||||
| 25 | 8 | ); | |||||||||
| 26 | |||||||||||
| 27 | sub TColorItem() { __PACKAGE__ } | ||||||||||
| 28 | 1 | ▶ | sub new_TColorItem { __PACKAGE__->from(@_) } | ||||||||
|
Subroutine
new_TColorItem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 29 | |||||||||||
| 30 | # public attributes | ||||||||||
| 31 | 8 | ▶ | our %HAS; BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||
| 32 | %HAS = ( | ||||||||||
| 33 | 0 | ▶ | name => sub { '' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 34 | 0 | ▶ | index => sub { 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 9 | ▶ | next => sub { undef }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 8 | ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 13 | ▶ | sub new { # \$item (%args) | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 13 | state $sig = signature( | |||||||||
| 41 | method => 1, | ||||||||||
| 42 | named => [ | ||||||||||
| 43 | name => Str, { alias => 'nm' }, | ||||||||||
| 44 | index => PositiveOrZeroInt, { alias => 'idx' }, | ||||||||||
| 45 | next => Maybe[Object], { alias => 'nxt', optional => 1 }, | ||||||||||
| 46 | ], | ||||||||||
| 47 | ); | ||||||||||
| 48 | 13 | my ( $class, $self ) = $sig->( @_ ); | |||||||||
| 49 | $self->{$_} = $HAS{$_}->() | ||||||||||
| 50 | 13 | for grep { not exists $self->{$_} } keys %HAS; | |||||||||
| 51 | 13 | bless $self, $class; | |||||||||
| 52 | 13 | Hash::Util::lock_keys( %$self ) if STRICT; | |||||||||
| 53 | 13 | return $self; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | sub from { # $item ($nm, $idx, |$nxt) | ||||||||
|
Subroutine
from: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | 1 | state $sig = signature( | |||||||||
| 58 | method => 1, | ||||||||||
| 59 | pos => [ | ||||||||||
| 60 | Str, | ||||||||||
| 61 | PositiveOrZeroInt, | ||||||||||
| 62 | Maybe[Object], { optional => 1 }, | ||||||||||
| 63 | ], | ||||||||||
| 64 | ); | ||||||||||
| 65 | 1 | my ( $class, @args ) = $sig->( @_ ); | |||||||||
| 66 | 1 | return $class->new( name => $args[0], index => $args[1], next => $args[2] ); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | sub add { # $i1 ($i1, $i2, |$swap) | ||||||||
|
Subroutine
add: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 70 | 2 | state $sig = signature( | |||||||||
| 71 | pos => [ | ||||||||||
| 72 | Object, | ||||||||||
| 73 | Object, | ||||||||||
| 74 | Bool, { optional => 1 } | ||||||||||
| 75 | ], | ||||||||||
| 76 | ); | ||||||||||
| 77 | 2 | my ( $i1, $i2, $swap ) = $sig->( @_ ); | |||||||||
| 78 | 2 | ▶ | assert ( not $swap ); # test if operands have been swapped | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 2 | ▶ | assert ( $i2->isa( TColorItem ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 2 | my $cur = $i1; | |||||||||
| 81 | $cur = $cur->{next} | ||||||||||
| 82 | 2 | ▶ | while $cur->{next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 2 | $cur->{next} = $i2; | |||||||||
| 84 | 2 | return $i1; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | use overload | ||||||||||
| 88 | 8 | ▶ | '+' => \&add, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 8 | fallback => 1; | |||||||||
| 90 | |||||||||||
| 91 | 8 | ▶ | my $mk_accessors = sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||
| 92 | 8 | my ( $pkg ) = @_; | |||||||||
| 93 | 8 | ▶ | assert ( @_ == 1 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 8 | ▶ | assert ( defined $pkg ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 8 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 96 | 8 | my %HAS = %{"${pkg}::HAS"}; | |||||||||
| 97 | 8 | for my $field ( keys %HAS ) { | |||||||||
| 98 | 24 | my $full_name = "${pkg}::$field"; | |||||||||
| 99 | 20 | ▶ | *$full_name = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||
| 100 | 20 | ▶ | assert ( is_Object $_[0] ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 20 | ▶ | if ( @_ > 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | $_[0]->{$field} = $_[1]; | |||||||||
| 103 | } | ||||||||||
| 104 | 20 | $_[0]->{$field}; | |||||||||
| 105 | 24 | }; | |||||||||
| 106 | } | ||||||||||
| 107 | 8 | }; | |||||||||
| 108 | |||||||||||
| 109 | 8 | __PACKAGE__->$mk_accessors(); | |||||||||
| 110 | |||||||||||
| 111 | 8 | 1 | |||||||||
| 112 | |||||||||||
| 113 | __END__ | ||||||||||