File: Test.pm

package info (click to toggle)
libconfig-mvp-perl 2.101650-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 228 kB
  • ctags: 59
  • sloc: perl: 595; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 769 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Config::MVP::Reader::Test;
use Moose;
extends 'Config::MVP::Reader';
with qw(Config::MVP::Reader::Findable::ByExtension);

sub default_extension { 'mvp-test' }

sub read_into_assembler {
  my ($self, $location, $assembler) = @_;

  my $filename = $location;

  open my $fh, '<', $filename or die "can't read $filename: $!";

  LINE: while (my $line = <$fh>) {
    chomp $line;
    next if $line =~ m{\A\s*(;.+)?\z}; # skip blanks, comments

    if ($line =~ m{\A(\S+)\s*=\s*(\S+)\z}) {
      $assembler->add_value($1, $2);
      next LINE;
    }

    if ($line =~ m{\A\[(\S+)(?:\s+(\S+?))?\]\z}) {
      $assembler->change_section($1, $2);
      next LINE;
    }

    die "don't know how to handle this line: $line\n";
  }

  return $assembler->sequence;
}

1;