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