l33t/Operators.pm

filter: Statementstmt 88.5% 100 / 113 Branchbran 64.2% 18 / 28 Conditioncond 38.8% 7 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 94.4% 17 / 18 Podpod 0.0% 0 / 1 totaltotal 76.6% 144 / 188 CC 22 SCAR 15.7
CC
22
Cov
79%
_rd
12.0
_if
9.7
_con
6.3
CRAP 4.8
↑ Summary l33t.pm »
1 package Language::l33t::Operators;
2 5 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Implementation of the l33t language operators
4 5 $Language::l33t::Operators::VERSION = '1.0.1';
5 5 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 requires qw/ _incr_op_ptr _incr_mem_ptr _incr_mem /;
13  
14 5 const our $NOP => 0;
15 5 const our $WRT => 1;
16 5 const our $RD => 2;
17 5 const our $IF => 3;
18 5 const our $EIF => 4;
19 5 const our $FWD => 5;
20 5 const our $BAK => 6;
21 5 const our $INC => 7;
22 5 const our $DEC => 8;
23 5 const our $CON => 9;
24 5 const our $END => 10;
25  
26 5 our @op_codes;
27  
28 5 $op_codes[$NOP] = \&_nop;
29 5 $op_codes[$WRT] = \&_wrt;
30 5 $op_codes[$RD] = \&_rd;
31 5 $op_codes[$IF] = \&_if;
32 5 $op_codes[$EIF] = \&_eif;
33 5 $op_codes[$FWD] = \&_fwd;
34 5 $op_codes[$BAK] = \&_bak;
35 5 $op_codes[$INC] = \&_inc;
36 5 $op_codes[$DEC] = \&_dec;
37 5 $op_codes[$CON] = \&_con;
38 5 $op_codes[$END] = \&_end;
39  
40 ▶sub opcode($self,$index) {
Subroutine opcode: called CC=3 SCAR=11.0
Pod undocumented
41 477 ▶ if ( $index > $#op_codes or $index < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index > $#Language::l33t::Operators::op_codes or $index < 0) 1 476 477
Condition66%2/3
$index > $#Language::l33t::Operators::op_codes or $index < 0
l!l&&r!l&&!r
10476
MC/DC50%1/2
$index > $#Language::l33t::Operators::op_codes or $index < 0
$index > $#Language::l33t::Operators::op_codes $index < 0
Truth table66%2/3
A or B
A= $index > $#Language::l33t::Operators::op_codesB= $index < 0
ABresult
1X1
011
000
42 1 warn "j00 4r3 teh 5ux0r\n";
43 1 $index = $NOP;
44 }
45 477 return $op_codes[ $index ]->( $_[0] );
46 }
47  
48  
49 127 ▶sub _inc($self,$sign=1) {
Subroutine _inc: called CC=2 SCAR=6.9
50 127 $self->_incr_op_ptr;
51 127 $self->_incr_mem( $sign * ( 1 + $self->memory_cell( $self->op_ptr ) ) );
52 127 $self->_incr_op_ptr;
53 127 return 1;
54 }
55  
56 ▶sub _dec($self) {
Subroutine _dec: called CC=1 SCAR=0.0
57 80 return $self->_inc( -1 );
58 }
59  
60 ▶sub _nop($self) {
Subroutine _nop: called CC=1 SCAR=0.0
61 184 $self->_incr_op_ptr;
62 184 return 1;
63 }
64  
65 sub _end {
66 11 ▶ return 0;
Subroutine _end: called CC=1 SCAR=0.0
67 }
68  
69  
70 ▶sub _con($self) {
Subroutine _con: called CC=6 SCAR=18.4
71 my $ip = join '.', map {
72 1 my $x = $self->_get_current_mem;
73 4 $self->_incr_mem_ptr;
74 4 ▶ $x || 0;
Branch: 1 branch
BranchTrueFalseTotal
$x or 0 2 2 4
75 } 1..4;
76  
77 1 ▶ my $port = ( $self->_get_current_mem() || 0 ) << 8;
Condition50%1/2
$self->_get_current_mem || 0
l!l
10
MC/DC0%0/1
$self->_get_current_mem || 0
$self->_get_current_mem
Truth table50%1/2
A
A= $self->_get_current_mem
Aresult
11
00
78 1 $self->_incr_mem_ptr;
79 {
80 5 ▶ no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 $port += $self->_get_current_mem;
82 }
83  
84 1 $self->_incr_mem_ptr( -5 );
85  
86 1 ▶ warn "trying to connect at $ip:$port\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 1 1
87 if $self->debug;
88  
89 1 ▶ if ( "$ip:$port" eq '0.0.0.0:0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("${ip}:$port" eq '0.0.0.0:0') { } 0 1 1
90 0 $self->set_socket( undef );
91 }
92 else {
93 1 ▶ if ( my $sock = IO::Socket::INET->new( "$ip:$port" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = 'IO::Socket::INET'->new("${ip}:$port")) { } 0 1 1
94 0 $self->set_socket( $sock );
95 }
96 else {
97 1 warn "h0s7 5uXz0r5! c4N'7 c0Nn3<7 101010101 l4m3R !!!\n";
98 }
99 }
100  
101 1 $self->_incr_op_ptr;
102 1 return 1;
103 }
104  
105  
106 sub _fwd {
107 98 ▶ my $self = shift;
Subroutine _fwd: called CC=2 SCAR=6.9
108 98 ▶ my $direction = shift || 1;
Condition100%2/2
shift() || 1
l!l
4949
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
109 98 $self->_incr_op_ptr;
110 98 $self->_incr_mem_ptr( $direction * ( 1 + $self->_current_op ) );
111 98 $self->_incr_op_ptr;
112  
113 98 return 1;
114 }
115  
116 49 ▶sub _bak { return $_[0]->_fwd( -1 ); }
Subroutine _bak: called CC=1 SCAR=0.0
117  
118 ▶sub _wrt($self) {
Subroutine _wrt: called CC=3 SCAR=11.7
119 18 ▶ if ( my $io = $self->socket || $self->stdout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $io = $self->socket || $self->stdout) { } 18 0 18
Condition33%1/3
$self->socket || $self->stdout
l!l&&r!l&&!r
0180
MC/DC0%0/2
$self->socket || $self->stdout
$self->socket $self->stdout
Truth table33%1/3
A || B
A= $self->socketB= $self->stdout
ABresult
1X1
011
000
120 5 ▶ no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 18 print {$io} chr $self->_get_current_mem;
122 }
123 else {
124 0 print chr $self->_get_current_mem;
125 }
126 18 $self->_incr_op_ptr;
127  
128 18 return 1;
129 }
130  
131 ▶sub _rd($self) {
Subroutine _rd: not called CC=3 SCAR=24.8
132 0 my $chr;
133  
134 0 ▶ if ( my $io = $self->socket || $self->stdin ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $io = $self->socket || $self->stdin) { } 0 0 0
Condition0%0/3
$self->socket || $self->stdin
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->socket || $self->stdin
$self->socket $self->stdin
Truth table0%0/3
A || B
A= $self->socketB= $self->stdin
ABresult
1X1
011
000
135 0 read $io, $chr, 1;
136 }
137 else {
138 0 read STDIN, $chr, 1;
139 }
140  
141 0 $self->_set_current_mem( ord $chr );
142 0 $self->_incr_op_ptr;
143  
144 0 return 1;
145 }
146  
147  
148 ▶sub _if($self) {
Subroutine _if: called CC=7 SCAR=22.7
149 44 ▶ if ( $self->_get_current_mem ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_current_mem) { } 43 1 44
150 43 $self->_nop;
151 }
152 else {
153 1 my $nest_level = 0;
154 1 my $max_iterations = $self->memory_size;
155  
156 SCAN:
157 1 while (1) {
158 3 $self->_incr_op_ptr;
159 3 $max_iterations--;
160  
161 3 ▶ $nest_level++ and redo if $self->_current_op == $IF;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_current_op == $Language::l33t::Operators::IF 0 3 3
Condition20%1/5
$self->_current_op == $Language::l33t::Operators::IF && ($nest_level++ && (redo))
!ll&&!rl&&r
300
$nest_level++ and redo
!ll
00
MC/DC0%0/2
$self->_current_op == $Language::l33t::Operators::IF && ($nest_level++ && (redo))
$self->_current_op == $Language::l33t::Operators::IF $nest_level++
Truth table33%1/3
A && B
A= $self->_current_op == $Language::l33t::Operators::IFB= $nest_level++
ABresult
0X0
100
111
162  
163 3 ▶ if ( $self->_current_op == $EIF ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_current_op == $Language::l33t::Operators::EIF) 0 3 3
164 0 ▶ if ( $nest_level ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nest_level) { } 0 0 0
165 0 $nest_level--;
166 }
167 else {
168 0 break SCAN;
169 }
170 }
171  
172 3 ▶ croak "dud3, wh3r3's my EIF?" unless $max_iterations;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_iterations 1 2 3
173 }
174 }
175  
176 43 return 1;
177 }
178  
179 ▶sub _eif($self) {
Subroutine _eif: called CC=3 SCAR=11.0
180 43 ▶ if ( ! $self->_get_current_mem ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_get_current_mem) { } 6 37 43
181 6 $self->_nop;
182 }
183 else {
184 37 ▶ $self->_incr_op_ptr( -1 ) until $self->_current_op == 3;
Branch: 1 branch
BranchTrueFalseTotal
$self->_current_op == 3 or do { $self->_incr_op_ptr(-1) } 432 37 469
185 };
186  
187 43 return 1;
188 }
189  
190  
191 5 1;
192  
193 __END__
194  
195 =pod
196  
197 =encoding UTF-8
198  
199 =head1 NAME
200  
201 Language::l33t::Operators - Implementation of the l33t language operators
202  
203 =head1 VERSION
204  
205 version 1.0.1
206  
207 =head1 AUTHOR
208  
209 Yanick Champoux <yanick@cpan.org>
210  
211 =head1 COPYRIGHT AND LICENSE
212  
213 This software is copyright (c) 2006 by Yanick Champoux.
214  
215 This is free software; you can redistribute it and/or modify it under
216 the same terms as the Perl 5 programming language system itself.
217  
218 =cut
↑ Summary l33t.pm »