l33t.pm

filter: Statementstmt 93.4% 86 / 92 Branchbran 100% 12 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 83.8% 26 / 31 Podpod 100% 2 / 2 totaltotal 92.4% 135 / 146 CC 12 SCAR 6.5
CC
12
Cov
95%
run
5.0
_build__memory
3.0
__ANON__
2.0
CRAP 1.9
« l33t/Operators.pm ↑ Summary
1 package Language::l33t;
2 3 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: a l33t interpreter
4 3 $Language::l33t::VERSION = '1.1.0';
5 3 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use MooseX::MungeHas 'is_rw';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 with 'Language::l33t::Operators';
23  
24 3 ▶use Types::Standard qw/ Int ArrayRef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Type::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 my $l33tByteSize = Type::Tiny->new(
28 name => 'L33tByteSize',
29 parent => Int,
30 15 ▶ constraint => sub { $_ > 10 },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 0 ▶ message => sub { "Byt3 s1z3 must be at l34st 11, n00b!" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 3 );
33  
34 12 ▶has debug => sub { 0 };
Subroutine _build_debug: called CC=1 SCAR=0.0
35  
36 3 has code => ();
37  
38 has source => (
39 predicate => 1,
40 clearer => 1,
41 23 ▶ trigger => sub($self,@) {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 23 $self->_clear_memory;
43 23 $self->_memory;
44 },
45 3 );
46  
47 3 has byte_size => ( is => 'ro', isa => $l33tByteSize, default => 256 );
48  
49 3 has _memory => (
50 writer => '_set_memory',
51 predicate => '_has_memory',
52 clearer => '_clear_memory',
53 isa => ArrayRef[Int],
54 lazy => 1,
55 builder => 1,
56 handles_via => 'Array',
57 handles => {
58 memory => 'elements',
59 set_memory_cell => 'set',
60 memory_size => 'count',
61 memory_cell => 'get',
62 },
63 );
64  
65 23 ▶sub _build__memory($self) {
Subroutine _build__memory: called CC=3 SCAR=11.0
66 23 my @memory = ( map ( { my $s = 0;
67 305 ▶ $s += $& while /\d/g;
Branch: 1 branch
BranchTrueFalseTotal
/\d/gu and do { $s += $& } 446 305 751
68 305 $s % $self->byte_size
69 } split ' ', $self->source ), 0 );
70  
71  
72 23 ▶ die "F00l! teh c0d3 1s b1g3R th4n teh m3m0ry!!1!\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->memory_max_size < @memory 2 21 23
73 if $self->memory_max_size < @memory;
74  
75 21 $self->mem_ptr( $#memory );
76 21 return [ @memory ];
77 }
78  
79 3 has memory_max_size => (
80 is => 'ro',
81 default => 64 * 1024,
82 );
83  
84 3 has mem_ptr => ();
85  
86 3 has op_ptr => (
87 isa => Int,
88 default => 0,
89 );
90  
91 23 ▶after _clear_memory => sub($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 23 $self->op_ptr(0);
93 23 $self->mem_ptr(0);
94 3 };
95  
96 0 ▶sub reset($self) {
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
97 0 $self->_clear_memory;
98 0 $self->memory;
99 }
100  
101  
102 0 ▶has stdout => sub { return \*STDOUT; };
Subroutine _build_stdout: not called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
103 3 has stdin => ();
104 3 has socket => ();
105  
106 14 ▶before run => sub($self,@) {
Subroutine __ANON__: called CC=2 SCAR=6.9
107 14 ▶ die "L0L!!1!1!! n0 l33t pr0gr4m l04d3d, sUxX0r!\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_memory 1 13 14
108 unless $self->_has_memory;
109 3 };
110  
111 ▶sub run ( $self, $nbr_iterations = -1 ) {
Pod documented
112
113 ▶ while ( $self->_iterate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_iterate) 1 464 465
114 ▶ $nbr_iterations-- if $nbr_iterations != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $nbr_iterations != -1 1 464 465
115 return 1 unless $nbr_iterations;
116 }
117  
118 return 0;
119 }
120  
121 490 ▶sub _iterate($self) {
Subroutine _iterate: called CC=2 SCAR=6.9
122 490 my $op_id = $self->memory_cell( $self->op_ptr );
123
124 490 ▶ if ( $self->debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 465 488 953
125 3 ▶ no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 465 warn "memory: ", join( ':', $self->memory ), "\n";
127 465 warn "op_ptr: $self->op_ptr, ",
128 "mem_ptr: $self->mem_ptr, ",
129 "op: $op_id, ",
130 "mem: ", $self->_get_current_mem, "\n";
131 }
132  
133 488 return $self->opcode( $op_id );
134 }
135  
136 1088 ▶sub _incr_op_ptr {
Subroutine _incr_op_ptr: called CC=2 SCAR=6.9
137 1088 ▶ $_[0]->op_ptr( $_[0]->op_ptr + ( $_[1] || 1 ) );
Condition100%2/2
$_[1] || 1
l!l
432656
MC/DC100%1/1
$_[1] || 1
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
138 }
139  
140 104 ▶sub _incr_mem_ptr {
Subroutine _incr_mem_ptr: called CC=2 SCAR=6.9
141 104 my ( $self, $increment ) = @_;
142 104 ▶ $increment ||= 1;
Condition100%2/2
$increment ||= 1
l!l
995
MC/DC100%1/1
$increment ||= 1
$increment
Truth table100%2/2
A
A= $increment
Aresult
11
00
143 104 $self->mem_ptr( ( $self->mem_ptr + $increment ) % $self->byte_size );
144 }
145  
146 127 ▶sub _incr_mem {
Subroutine _incr_mem: called CC=1 SCAR=0.0
147 127 my ( $self, $increment ) = @_;
148 3 ▶ no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 127 $self->set_memory_cell( $self->mem_ptr =>
150 ( $self->memory_cell( $self->mem_ptr ) + $increment ) %
151 $self->byte_size );
152 }
153  
154 0 ▶sub _set_current_mem ($self, $value ) {
Subroutine _set_current_mem: not called CC=1 SCAR=6.9
155 0 return $self->memory_set( $self->mem_ptr => $value );
156 }
157  
158  
159 111 ▶sub _get_current_mem($self) {
Subroutine _get_current_mem: called CC=1 SCAR=0.0
160 111 return $self->memory_cell( $self->mem_ptr );
161 }
162  
163 573 ▶sub _current_op($self) {
Subroutine _current_op: called CC=2 SCAR=6.9
164 573 ▶ return $self->memory_cell( $self->op_ptr ) || 0;
Condition100%2/2
$self->memory_cell($self->op_ptr) || 0
l!l
268305
MC/DC100%1/1
$self->memory_cell($self->op_ptr) || 0
$self->memory_cell($self->op_ptr)
Truth table100%2/2
A
A= $self->memory_cell($self->op_ptr)
Aresult
11
00
165 }
166  
167 3 'End of Language::l33t';
168  
169 __END__
« l33t/Operators.pm ↑ Summary