File Coverage

blib/lib/Brackup/Metafile.pm
Criterion Covered Total %
statement 38 42 90.4
branch 9 14 64.2
condition n/a
subroutine 6 6 100.0
pod 0 3 0.0
total 53 65 81.5


line stmt bran cond sub pod time code
1             package Brackup::Metafile;
2 13     13   77 use strict;
  13         24  
  13         573  
3 13     13   77 use warnings;
  13         29  
  13         549  
4 13     13   71 use Carp qw(croak);
  13         27  
  13         23923  
5              
6             sub new {
7 13     13 0 33 my ($class) = @_;
8 13         67 return bless {}, $class;
9             }
10              
11             sub open {
12 13     13 0 49 my ($class, $file) = @_;
13 13 50       495 unless (-e $file) {
14 0         0 die "Unable to open metafile $file\n";
15             }
16 13         72 my $self = __PACKAGE__->new;
17 13         75 $self->{filename} = $file;
18 13 50       34 if (eval { require IO::Uncompress::AnyUncompress }) {
  13         178  
19 13 50       258 $self->{fh} = IO::Uncompress::AnyUncompress->new($file)
20             or die "Failed to open file $file: $IO::Uncompress::AnyUncompress::AnyUncompressError";
21             }
22             else {
23 0         0 open $self->{fh}, "<", $file;
24             }
25 13         20233 $self->{linenum} = 0;
26 13         76 return $self;
27             }
28              
29             sub readline {
30 211     211 0 329 my $self = shift;
31 211         388 my $ret = {};
32 211         242 my $line; #
33 211         296 my $fh = $self->{fh};
34 211         655 while (defined ($line = <$fh>)) {
35 1462         77316 $self->{linenum}++;
36 1462 100       6174 if ($line =~ /^([\w\-]+):\s*(.+)/) {
37 1228         4220 $ret->{$1} = $2;
38 1228         2494 $self->{last} = \$ret->{$1};
39 1228         3882 next;
40             }
41 234 100       774 if ($line eq "\n") {
42 198         14565 return $ret;
43             }
44 36 50       187 if ($line =~ /^\s+(.+)/) {
45 36 50       105 die "Can't continue line without start" unless $self->{last};
46 36         49 ${ $self->{last} } .= " $1";
  36         161  
47 36         136 next;
48             }
49              
50 0         0 $line =~ s/[^[:print:]]/?/g;
51 0         0 die "Unexpected line in metafile $self->{filename}, line $self->{linenum}: $line";
52             }
53 13         633 return undef;
54             }
55              
56             1;