| 1 | package Brackup::Metafile; | ||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 9 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 7 | 9 | my ($class) = @_; | |||||||||
| 8 | 9 | return bless {}, $class; | |||||||||
| 9 | } | ||||||||||
| 10 | |||||||||||
| 11 | 9 | ▶ | sub open { | ||||||||
|
Subroutine
open: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||
| 12 | 9 | my ($class, $file) = @_; | |||||||||
| 13 | 9 | ▶ | unless (-e $file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | die "Unable to open metafile $file\n"; | |||||||||
| 15 | } | ||||||||||
| 16 | 9 | my $self = __PACKAGE__->new; | |||||||||
| 17 | 9 | $self->{filename} = $file; | |||||||||
| 18 | 9 | ▶ | if (eval { require IO::Uncompress::AnyUncompress }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 9 | ▶ | $self->{fh} = IO::Uncompress::AnyUncompress->new($file) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | or die "Failed to open file $file: $IO::Uncompress::AnyUncompress::AnyUncompressError"; | ||||||||||
| 21 | } | ||||||||||
| 22 | else { | ||||||||||
| 23 | 0 | open $self->{fh}, "<", $file; | |||||||||
| 24 | } | ||||||||||
| 25 | 9 | $self->{linenum} = 0; | |||||||||
| 26 | 9 | return $self; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 148 | ▶ | sub readline { | ||||||||
|
Subroutine
readline: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||
| 30 | 148 | my $self = shift; | |||||||||
| 31 | 148 | my $ret = {}; | |||||||||
| 32 | 148 | my $line; # | |||||||||
| 33 | 148 | my $fh = $self->{fh}; | |||||||||
| 34 | 148 | ▶ | while (defined ($line = <$fh>)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1021 | $self->{linenum}++; | |||||||||
| 36 | 1021 | ▶ | if ($line =~ /^([\w\-]+):\s*(.+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 856 | $ret->{$1} = $2; | |||||||||
| 38 | 856 | $self->{last} = \$ret->{$1}; | |||||||||
| 39 | 856 | next; | |||||||||
| 40 | } | ||||||||||
| 41 | 165 | ▶ | if ($line eq "\n") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 139 | return $ret; | |||||||||
| 43 | } | ||||||||||
| 44 | 26 | ▶ | if ($line =~ /^\s+(.+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 26 | ▶ | die "Can't continue line without start" unless $self->{last}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 26 | ${ $self->{last} } .= " $1"; | |||||||||
| 47 | 26 | next; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | $line =~ s/[^[:print:]]/?/g; | |||||||||
| 51 | 0 | die "Unexpected line in metafile $self->{filename}, line $self->{linenum}: $line"; | |||||||||
| 52 | } | ||||||||||
| 53 | 9 | return undef; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 13 | 1; | |||||||||