12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package SugarTrail::Repo::Filesystem;
- # provide access to STM data
- # * init()
- # * load_text()
- # * load_vcs()
-
- use strict;
- use warnings;
- use parent 'SugarTrail::Repo';
- use Carp;
-
- # initialize repo
- sub new {
- my $class = shift;
- my $args = { @_ };
- exists($args->{$_}) or croak "missing mandatory parameter: $_" foreach (qw/root/);
- my $self = { %$args };
- unless (-d $args->{root}) {
- $self->{last_error} = "invalid repository root directory: " . $args->{root};
- carp $self->{last_error};
- }
- return bless $self, $class;
- }
-
- sub load_text {
- my $self = shift;
- my $args = { @_ };
-
- # load
- my $fn = $self->{root} . $args->{stm};
- my $fh;
- unless (open $fh, "<", $fn) {
- $self->{last_error} = "cannot open STM file $fn for reading: $!";
- carp $self->{last_error};
- return;
- }
- my $text = join "", <$fh>;
- close $fh;
-
- return $text;
- }
-
- 1;
|