blib/lib/Cikl/Smrt/Parsers/ParseDelim.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 80 CC 7 SCAR 33.7
CC
7
Cov
0%
parse
56.0
name
2.0
BEGIN
2.0
CRAP 29.0
1 package Cikl::Smrt::Parsers::ParseDelim;
2  
3 use strict;
4 use warnings;
5  
6 use Mouse;
7 use Cikl::Smrt::Parser;
8 extends 'Cikl::Smrt::Parser';
9 use namespace::autoclean;
10  
11 use constant NAME => 'delimiter';
12 sub name { return NAME; }
13  
14 has 'delimiter' => (
15 is => 'ro',
16 isa => 'Str',
17 required => 1
18 );
19  
20 has 'feed_limit' => (
21 is => 'ro',
22 );
23  
24 has 'values' => (
25 is => 'ro',
26 isa => 'Str',
27 required => 1
28 );
29  
30 has 'skipfirst' => (
31 is => 'ro',
32 isa => 'Num',
33 default => 0
34 );
35  
36 sub parse {
37 my $self = shift;
38 my $fh = shift;
39 my $broker = shift;
40  
41 my $split = $self->delimiter;
42  
43 my @cols = split(/\s*,\s*/, $self->values);
44
45 my $start = 0;
46 my $end = undef;
47 if(my $l = $self->feed_limit){
48 if(ref($l) eq 'ARRAY'){
49 ($start,$end) = @{$l};
50 } else {
51 ($start,$end) = (0,$l-1);
52 }
53 }
54 $start += 1 if($self->skipfirst);
55  
56 # Find our way to the first line we need to read.
57 my $lineno = -1;
58 while (!$fh->eof()) {
59 $lineno++;
60 last if (defined($end) && $lineno > $end);
61  
62 my $line = $fh->getline();
63  
64 next if $lineno < $start;
65 next if ($line =~ /^(#|$|<)/);
66  
67 $line =~ s/[\r\n]+$//;
68  
69 my @m = split($split,$line);
70 my $h = {};
71 foreach (0 ... $#cols){
72 $h->{$cols[$_]} = $m[$_];
73 }
74 $broker->emit($h);
75 }
76  
77 return(undef);
78 }
79  
80 __PACKAGE__->meta->make_immutable;
81  
82 1;