Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

szabgab / perl5-markua-parser / 11

7 Mar 2018 - 22:17 coverage: 96.97% (+2.5%) from 94.444%
11

push

travis-ci

0a4c12791c9e13fda6624553bb72bc55?size=18&default=identiconszabgab
parse paragraphs as well

32 of 33 relevant lines covered (96.97%)

23.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/lib/Markua/Parser.pm
1
package Markua::Parser;
2
use strict;
4×
3
use warnings;
4×
4
use Path::Tiny qw(path);
4×
5

6
our $VERSION = 0.01;
7

8
sub new {
9
    my ($class) = @_;
4×
10
    my $self = bless {}, $class;
4×
11
    return $self;
4×
12
}
13

14
sub parse_file {
15
    my ($self, $filename) = @_;
12×
16
    my @entries;
12×
17
    my @errors;
18
    my $cnt = 0;
12×
19

20
    $self->{text} = '';
12×
21

22
    for my $line (path($filename)->lines_utf8) {
12×
23
        $cnt++;
88×
24
        if ($line =~ /^(#{1,6}) (\S.*)/) {
88×
25
            push @entries, {
28×
26
                tag => 'h' . length($1),
27
                text => $2,
28
            };
29
            next;
28×
30
        }
31

32
        # anything else defaults to paragraph
33
        if ($line =~ /\S/) {
60×
34
            $self->{tag} = 'p';
20×
35
            $self->{text} .= $line;
20×
36
            next;
20×
37
        }
38

39
        if ($line =~ /^\s*$/) {
40×
40
            $self->save_tag(\@entries);
40×
41
            next;
40×
42
        }
43

44
        push @errors, {
!
45
            row => $cnt,
46
            line => $line,
47
        }
48
    }
49
    $self->save_tag(\@entries);
12×
50
    return \@entries, \@errors;
12×
51
}
52

53
sub save_tag {
54
    my ($self, $entries) = @_;
52×
55

56
    if ($self->{tag}) {
52×
57
        $self->{text} =~ s/\n+\Z//;
12×
58
        push @$entries, {
59
            tag => $self->{tag},
60
            text => $self->{text},
61
        };
62
        $self->{tag} = undef;
12×
63
        $self->{text} = '';
12×
64
    }
65
    return;
52×
66
}
67

68

69
1;
70

Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc