Browse Source

Added class SugarTrail::STM

Alois Mahdal 11 years ago
parent
commit
ab5e3e0914
2 changed files with 43 additions and 2 deletions
  1. 3
    2
      lib/SugarTrail/Repo.pm
  2. 40
    0
      lib/SugarTrail/STM.pm

+ 3
- 2
lib/SugarTrail/Repo.pm View File

@@ -7,6 +7,7 @@ use strict;
7 7
 use warnings;
8 8
 use Carp;
9 9
 use helper;
10
+use SugarTrail::STM;
10 11
 
11 12
 # initialize repo
12 13
 sub new {
@@ -23,11 +24,11 @@ sub load_stm {
23 24
     my $self = shift;
24 25
     my $args = { @_ };
25 26
 
26
-    my $stm = {};
27
+    my $stm = SugarTrail::STM->new();
27 28
     $stm->{text} = $self->load_text(stm => $args->{stm})
28 29
         or return;
29 30
 
30
-    return bless $stm, 'SugarTrail::STM';
31
+    return $stm;
31 32
 }
32 33
 
33 34
 1;

+ 40
- 0
lib/SugarTrail/STM.pm View File

@@ -0,0 +1,40 @@
1
+package SugarTrail::STM;
2
+# STM holder
3
+# new()
4
+# parse_headers()
5
+
6
+
7
+
8
+use strict;
9
+use warnings;
10
+use Carp;
11
+
12
+sub new {
13
+    my $class = shift;
14
+    my $args = { @_ };
15
+    my $self = {};
16
+    $self->{args} = $args;
17
+    return bless $self, $class;
18
+}
19
+
20
+sub parse_headers {
21
+    my $self = shift;
22
+
23
+    my ($head, $body) = split "\n\n", $self->{text}, 2;
24
+
25
+    my @lines = split "\n", $head;
26
+
27
+    $self->{head} = $head;
28
+    $self->{body} = $body;
29
+
30
+    foreach (@lines) {
31
+        my ($n, $v) = split ": ", $_, 2;
32
+        $self->{meta}->{$n} = $v;
33
+    }
34
+
35
+    return 1;
36
+
37
+}
38
+
39
+
40
+1;