EPL2/Command/A.pm

filter: Statementstmt 92.5% 62 / 67 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.3% 12 / 13 Podpod 100% 1 / 1 totaltotal 79.4% 81 / 102 CC 8 SCAR 8.7
CC
8
Cov
83%
multi_lines
4.1
_b_height
3.8
_b_width
3.3
CRAP 2.4
« EPL2/Types.pm ↑ Summary EPL2/Command/Q.pm »
1 package EPL2::Command::A;
2 # ABSTRACT: A Command (ASCII Text)
3 3 $EPL2::Command::A::VERSION = '0.001';
4 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use MooseX::Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use EPL2::Types ( 'Natural', 'Rotation', 'Mult', 'Reverse', 'Font', 'Text' );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Text::Wrap::Smart::XS 'exact_wrap';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 extends 'EPL2::Command';
12  
13 #Public Attributes
14 3 has h_pos => ( is => 'rw', isa => Natural, default => 0 );
15 3 has v_pos => ( is => 'rw', isa => Natural, default => 0 );
16 3 has rotation => ( is => 'rw', isa => Rotation, default => 0 );
17 3 has font => ( is => 'rw', isa => Font, default => 1 );
18 3 has h_mult => ( is => 'rw', isa => Mult, default => 1 );
19 3 has v_mult => ( is => 'rw', isa => Mult, default => 1 );
20 3 has 'reverse' => ( is => 'rw', isa => Reverse, default => 'N' );
21 3 has text => ( is => 'ro', isa => Text, required => 1 );
22  
23 #Private Attributes
24 3 has width => ( is => 'ro', init_arg => undef, builder => '_b_width', lazy => 1 );
25 3 has height => ( is => 'ro', init_arg => undef, builder => '_b_height', lazy => 1 );
26 3 has fonts => ( is => 'ro', init_arg => undef, builder => '_b_fonts' );
27  
28 #Builders
29 3 ▶sub _b_width {
Subroutine _b_width: called CC=3 SCAR=12.0
30 3 my ($self) = @_;
31 3 my $txt = $self->text;
32 3 $txt =~ s/^"//;
33 3 $txt =~ s/"$//;
34 3 ▶ if ( !$self->rotation || $self->rotation == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->rotation or $self->rotation == 2) 3 0 3
Condition33%1/3
not $self->rotation or $self->rotation == 2
l!l&&r!l&&!r
300
MC/DC0%0/2
not $self->rotation or $self->rotation == 2
not $self->rotation $self->rotation == 2
Truth table33%1/3
not(A) or B
A= not $self->rotationB= $self->rotation == 2
ABresult
1X1
011
000
35 3 return $self->_b_fonts->{ $self->font }{width} * length( $txt );
36 }
37 0 return $self->_b_fonts->{$self->font}{height};
38 }
39 3 ▶sub _b_height {
Subroutine _b_height: called CC=3 SCAR=13.3
40 3 my ($self) = @_;
41 3 ▶ if ( !$self->rotation || $self->rotation == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->rotation or $self->rotation == 2) 3 0 3
Condition33%1/3
not $self->rotation or $self->rotation == 2
l!l&&r!l&&!r
300
MC/DC0%0/2
not $self->rotation or $self->rotation == 2
not $self->rotation $self->rotation == 2
Truth table33%1/3
not(A) or B
A= not $self->rotationB= $self->rotation == 2
ABresult
1X1
011
000
42 3 return $self->_b_fonts->{$self->font}{height};
43 }
44 0 return $self->_b_fonts->{ $self->font }{width} * length( $self->text );
45 }
46 10 ▶sub _b_fonts {
Subroutine _b_fonts: called CC=1 SCAR=0.0
47 return {
48 (
49 10 1 => { width => 8 + 2, height => 12 + 2 },
50 2 => { width => 10 + 2, height => 16 + 2 },
51 3 => { width => 12 + 2, height => 20 + 2 },
52 4 => { width => 14 + 2, height => 24 + 2 },
53 5 => { width => 32 + 2, height => 48 + 2 }
54 )
55 };
56 }
57  
58 #Methods
59 0 ▶method string ( Str :$delimiter = "\n" ) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.6
Subroutine string: called CC=1 SCAR=0.6
60 0 sprintf 'A%d,%d,%d,%d,%d,%d,%s,%s%s',
61 $self->h_pos, $self->v_pos, $self->rotation, $self->font,
62 $self->h_mult, $self->v_mult, $self->reverse, $self->text,
63 $delimiter;
64 3 }
65  
66 1 ▶sub multi_lines {
Subroutine multi_lines: called CC=4 SCAR=14.1
Pod documented
67 1 my $class = shift;
68 1 my %args = @_;
69 1 my ( @A, $txt );
70 1 $txt = $args{text};
71 1 $txt =~ s/( \r | \n | \t )//mxg;
72 1 $txt =~ s/^"//;
73 1 $txt =~ s/"$//;
74 1 my @chunks = exact_wrap($txt, $args{length});
75 1 delete $args{text};
76 1 delete $args{length};
77 1 for my $chunk ( @chunks ) {
78 2 my $A = $class->new( %args, text => qq{"$chunk"} );
79 2 ▶ if ( !$args{rotation} || $args{rotation} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'rotation'} or $args{'rotation'} == 2) { } 2 0 2
Condition33%1/3
not $args{"rotation"} or $args{"rotation"} == 2
l!l&&r!l&&!r
200
MC/DC0%0/2
not $args{"rotation"} or $args{"rotation"} == 2
not $args{"rotation"} $args{"rotation"} == 2
Truth table33%1/3
not(A) or B
A= not $args{"rotation"}B= $args{"rotation"} == 2
ABresult
1X1
011
000
80 2 $args{v_pos} = $A->v_pos + $A->height;
81 }
82 else {
83 0 $args{h_pos} = $A->h_pos + $A->width;
84 }
85 2 push @A, $A
86 }
87 1 return @A;
88 }
89  
90 3 __PACKAGE__->meta->make_immutable;
91  
92 3 1;
93  
94 __END__
« EPL2/Types.pm ↑ Summary EPL2/Command/Q.pm »