12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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 _get_filename {
- my $self = shift;
- my $source = shift;
- return $self->{root} . $source;
- }
-
- sub get_revision {
- my $self = shift;
- my $source = shift // $self->{source};
- my $file = $self->_get_filename($source);
- return (stat($file))[9]; # 9 = mtime
- }
-
- sub load_text {
- my $self = shift;
- my $source = shift;
-
- # load
- my $fn = $self->_get_filename($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;
|