File Coverage

blib/lib/BeamerReveal/TemplateStore.pm
Criterion Covered Total %
statement 9 36 25.0
branch 0 12 0.0
condition 0 3 0.0
subroutine 3 7 42.8
pod 3 3 100.0
total 15 61 24.5


line stmt bran cond sub pod time code
1             # -*- cperl -*-
2             # ABSTRACT: TemplateStore
3              
4              
5             package BeamerReveal::TemplateStore;
6             our $VERSION = '20260208.1851'; # VERSION
7              
8 1     1   9 use parent 'Exporter';
  1         2  
  1         12  
9 1     1   86 use Carp;
  1         2  
  1         102  
10              
11 1     1   8 use BeamerReveal::Log;
  1         3  
  1         696  
12              
13             my $store = undef;
14              
15              
16             sub new {
17 0     0 1   my $class = shift;
18            
19 0 0         $class = (ref $class ? ref $class : $class );
20 0           my $self = {};
21 0           bless $self, $class;
22             }
23              
24              
25              
26             sub fetch {
27 0     0 1   my $self = shift;
28 0           my ( $library, $fileName ) = @_;
29              
30 0           my $key = $library . '/' . $fileName;
31 0 0         $store->{$key} = _readTemplate( $library, $fileName ) unless( exists $store->{$key} );
32 0           return $store->{$key};
33             }
34              
35              
36             sub stampTemplate {
37 0     0 1   my ( $string, $hash ) = @_;
38            
39 0           while( my ( $stamp, $value ) = each %$hash ) {
40 0 0         if ( defined( $value ) ) {
41 0           $string =~ s/---${stamp}---/$value/g;
42             }
43             else {
44 0           my $lcstamp = lc( $stamp );
45 0           $string =~ s/(?:${lcstamp}\s*[:=]\s*)?"?-*-${stamp}-*-"?//g;
46             }
47             }
48 0           return $string;
49             }
50              
51              
52             sub _readTemplate {
53 0     0     my ( $library, $fileName ) = @_;
54              
55 0 0         my $home = $^O eq 'MSWin32' ? $ENV{'userprofile'} : $ENV{'HOME'};
56 0   0       my $configDir = $ENV{'BEAMERREVEAL_CONFIG'}
57             // "$home/.config/BeamerReveal";
58 0           my $templateFileName = "$configDir/templates/$library/$fileName";
59 0 0         $templateFileName = File::ShareDir::dist_dir( 'BeamerReveal' ) . "/templates/$library/$fileName"
60             if ( ! -r $templateFileName );
61            
62 0           my $templateFile = IO::File->new();
63 0 0         $templateFile->open( "<$templateFileName" )
64             or $BeamerReveal::Log::logger->fatal( "Error: installation incomplete - cannot find the template file '$fileName'" );
65 0           my $content = do { local $/; <$templateFile> };
  0            
  0            
66 0           return $content;
67             }
68              
69              
70             1;
71              
72             __END__