Parser library
authorJoachim Breitner <mail@joachim-breitner.de>
Tue, 12 Jun 2007 17:02:51 +0000 (17:02 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Tue, 12 Jun 2007 17:02:51 +0000 (17:02 +0000)
MetaInit::Parse.pm [new file with mode: 0644]

diff --git a/MetaInit::Parse.pm b/MetaInit::Parse.pm
new file mode 100644 (file)
index 0000000..8c62bba
--- /dev/null
@@ -0,0 +1,24 @@
+package MetaInit::Parse
+
+sub parse {
+    my $fh = shift;
+
+    my %parsed;
+    my $lastkey;
+    while (<$fh>) {
+        #last if /^$/;
+        if (my ($key, $value) = m/^([^ ].*): (.*)/) {
+            $parsed{$key} = $value;
+           $lastkey = $key;
+        }
+        elsif ($lastkey) {
+            s/^ //;
+            s/^\.$//;
+            $parsed{$lastkey} .= $_;
+        } else {
+           die "Cannot parse $!";
+       }
+    }
+    return %parsed;
+}
+