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