MinCaml/Code.pm

filter: Statementstmt 100% 51 / 51 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 20.0% 1 / 5 totaltotal 93.6% 74 / 79 CC 7 SCAR 6.0
CC
7
Cov
98%
forward
3.0
from_file
2.0
__ANON__
2.0
CRAP 1.8
« MinCaml/Parser.pm ↑ Summary MinCaml/Token.pm »
1 package Language::MinCaml::Code;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 __PACKAGE__->mk_ro_accessors(qw(line column));
8  
9 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
10 11 bless { buffer => q{},
11 line => 0,
12 column => 0,
13 next_line => undef
14 }, __PACKAGE__;
15 }
16  
17 8 ▶sub from_string {
Subroutine from_string: called CC=1 SCAR=0.0
Pod undocumented
18 8 my($class, $string) = @_;
19 8 my @lines = split(/\n/, $string);
20 8 my $self = $class->new;
21  
22 9 ▶ $self->{next_line} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
23 9 ▶ if (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) { } 6 3 9
24 6 $self->{buffer} = shift @lines;
25 6 $self->{line}++;
26 6 $self->{column} = 1;
27 }
28 else {
29 3 $self->{buffer} = q{};
30 3 $self->{line} = 0;
31 3 $self->{column} = 0;
32 }
33 9 return;
34 8 };
35  
36 8 $self->{next_line}->();
37 8 $self;
38 }
39  
40 2 ▶sub from_file {
Subroutine from_file: called CC=2 SCAR=6.9
Pod undocumented
41 2 my($class, $file_path) = @_;
42 2 ▶ my $handler = IO::File->new($file_path, 'r')
Branch: 1 branch
BranchTrueFalseTotal
my $handler = "IO::File"->new($file_path, "r") or croak("Can't open '${file_path}'.") 2 0 2
43 or croak "Can't open '$file_path'.";
44 2 my $self = $class->new;
45  
46 2 ▶ $self->{next_line} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
47 2 ▶ if ($handler->eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler->eof) { } 1 1 2
48 1 $handler->close;
49 1 $self->{buffer} = q{};
50 1 $self->{line} = 0;
51 1 $self->{column} = 0;
52 }
53 else {
54 1 $self->{buffer} = $handler->getline;
55 1 chomp $self->{buffer};
56 1 $self->{line}++;
57 1 $self->{column} = 1;
58 }
59 2 return;
60 2 };
61  
62 2 $self->{next_line}->();
63 2 $self;
64 }
65  
66 4 ▶sub buffer {
Subroutine buffer: called CC=2 SCAR=6.9
Pod undocumented
67 4 my $self = shift;
68 4 ▶ $self->{buffer} ? substr($self->{buffer}, $self->{column} - 1) : q{};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'buffer'} ? : 3 1 4
69 }
70  
71 3 ▶sub forward {
Subroutine forward: called CC=3 SCAR=11.0
Pod undocumented
72 3 my($self, $number) = @_;
73 3 ▶ $self->{column} += $number if $self->{buffer};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"buffer"} 2 1 3
74 3 ▶ $self->{next_line}->() if $self->{column} > length($self->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"column"} > length $self->{"buffer"} 1 2 3
75 3 return;
76 }
77  
78 5 1;
« MinCaml/Parser.pm ↑ Summary MinCaml/Token.pm »