| 1 | package Image::TextMode::Pixel; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use Types::Standard qw( Int ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Attribute byte constants | ||||||||||||||||||||||||||||
| 7 | 30 | my $ATTR_BG_NB = 240; | |||||||||||||||||||||||||||
| 8 | 30 | my $ATTR_BLINK = 128; | |||||||||||||||||||||||||||
| 9 | 30 | my $ATTR_BG = 112; | |||||||||||||||||||||||||||
| 10 | 30 | my $ATTR_FG = 15; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | has 'char' => ( is => 'rw', isa => sub { die '$_[ 0 ] is not a single character' unless length( $_[ 0 ] ) == 1 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 30 | has 'fg' => ( | |||||||||||||||||||||||||||
| 15 | is => 'rw', | ||||||||||||||||||||||||||||
| 16 | isa => Int, | ||||||||||||||||||||||||||||
| 17 | default => 0, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 30 | has 'bg' => ( | |||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | isa => Int, | ||||||||||||||||||||||||||||
| 23 | default => 0, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 30 | has 'blink' => ( | |||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | isa => Int, | ||||||||||||||||||||||||||||
| 29 | default => 0, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 NAME | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Image::TextMode::Pixel - A base class to represent a text mode "pixel" | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Represents a "pixel; i.e. a character plus, foreground and background colors and | ||||||||||||||||||||||||||||
| 39 | an blink mode setting. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item * char - The character for the pixel | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item * fg - The foreground palette index | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =item * bg - The background palette index | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =item * blink - The blink bit | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =back | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 METHODS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head2 new( %args ) | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Creates a new pixel. If you supply an C<attr> argument, then it will be | ||||||||||||||||||||||||||||
| 60 | broken down into its components (fg, bg, and blink). By default, blink mode | ||||||||||||||||||||||||||||
| 61 | is off (aka iCEColor is on). Pass a true value for C<blink_mode> to enabled | ||||||||||||||||||||||||||||
| 62 | it. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 BUILDARGS( %args ) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | A Moose override to extract the C<attr> key and convert it to components, | ||||||||||||||||||||||||||||
| 67 | should it exist. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub BUILDARGS { | ||||||||||||||||||||||||||||
| 72 | 3 | ▶ | my ( $class, @rest ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | my $options = {}; | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | if ( @rest % 2 != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | $options = pop @rest; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 3 | my %args = @rest; | |||||||||||||||||||||||||||
| 80 | 3 | my $attr = delete $args{ attr }; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if ( $attr ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 2 | $attr = $class->_attr_to_components( $attr, $options ); | |||||||||||||||||||||||||||
| 84 | 2 | %args = ( %args, %$attr ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | return \%args; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub _attr_to_components { | ||||||||||||||||||||||||||||
| 91 | 2 | ▶ | my ( $self, $attr, $options ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_attr_to_components: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||
| 93 | 2 | my $blink = $options->{ blink_mode }; | |||||||||||||||||||||||||||
| 94 | 2 | my %data; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 2 | $data{ fg } = $attr & $ATTR_FG; | |||||||||||||||||||||||||||
| 97 | 2 | ▶ | $data{ bg } = ( $attr & ( $blink ? $ATTR_BG : $ATTR_BG_NB ) ) >> 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | $data{ blink } = ( $attr && $ATTR_BLINK ) >> 7 if $blink; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$attr && $ATTR_BLINK
MC/DC0%0/2
$attr && $ATTR_BLINK
$attr
$ATTR_BLINK
Truth table33%1/3
A && B
A= $attrB= $ATTR_BLINK
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | return \%data; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Copyright 2008-2015 by Brian Cassidy | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 112 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 30 | 1; | |||||||||||||||||||||||||||