Browse Source

Added basic workflow parts

Alois Mahdal (@azzgoat) 11 years ago
parent
commit
7761a747ba
2 changed files with 76 additions and 0 deletions
  1. 33
    0
      lib/SugarTrail/Repo.pm
  2. 43
    0
      lib/SugarTrail/Repo/Filesystem.pm

+ 33
- 0
lib/SugarTrail/Repo.pm View File

@@ -0,0 +1,33 @@
1
+package SugarTrail::Repo;
2
+# provide access to STM objects
3
+#
4
+# * load_stm()
5
+
6
+use strict;
7
+use warnings;
8
+use Carp;
9
+use helper;
10
+
11
+# initialize repo
12
+sub new {
13
+    my $class   = shift;
14
+    my $args    = { @_ };
15
+    exists($args->{type}) or $args->{type} = 'SugarTrail::Repo::Filesystem';
16
+    $class = $args->{type};
17
+    #TODO: remove use fail
18
+    use SugarTrail::Repo::Filesystem;
19
+    return $class->new(%$args);
20
+}
21
+
22
+sub load_stm {
23
+    my $self = shift;
24
+    my $args = { @_ };
25
+
26
+    my $stm = {};
27
+    $stm->{text} = $self->load_text(stm => $args->{stm})
28
+        or return;
29
+
30
+    return bless $stm, 'SugarTrail::STM';
31
+}
32
+
33
+1;

+ 43
- 0
lib/SugarTrail/Repo/Filesystem.pm View File

@@ -0,0 +1,43 @@
1
+package SugarTrail::Repo::Filesystem;
2
+# provide access to STM data
3
+# * init()
4
+# * load_text()
5
+# * load_vcs()
6
+
7
+use strict;
8
+use warnings;
9
+use parent 'SugarTrail::Repo';
10
+use Carp;
11
+
12
+# initialize repo
13
+sub new {
14
+    my $class   = shift;
15
+    my $args    = { @_ };
16
+    exists($args->{$_}) or croak "missing mandatory parameter: $_" foreach (qw/root/);
17
+    my $self    = { %$args };
18
+    unless (-d $args->{root}) {
19
+       $self->{last_error} = "invalid repository root directory: " . $args->{root};
20
+       carp $self->{last_error};
21
+    }
22
+    return bless $self, $class;
23
+}
24
+
25
+sub load_text {
26
+    my $self = shift;
27
+    my $args = { @_ };
28
+
29
+    # load
30
+    my $fn = $self->{root} . $args->{stm};
31
+    my $fh;
32
+    unless (open $fh, "<", $fn) {
33
+        $self->{last_error} = "cannot open STM file $fn for reading: $!";
34
+        carp $self->{last_error};
35
+        return;
36
+    }
37
+    my $text = join "", <$fh>;
38
+    close $fh;
39
+
40
+    return $text;
41
+}
42
+
43
+1;