123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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->{source};
- my $fh;
- unless (open $fh, "<", $fn) {
- $self->{last_error} = "cannot open master $fn for reading: $!";
- carp $self->{last_error};
- return;
- }
- my $text = join "", <$fh>;
- close $fh;
-
- return $text;
- }
-
- 1;
|