| 1 | # -*- cperl -*- | ||||||||||||
| 2 | # ABSTRACT: TemplateStore | ||||||||||||
| 3 | |||||||||||||
| 4 | |||||||||||||
| 5 | package BeamerReveal::TemplateStore; | ||||||||||||
| 6 | 1 | our $VERSION = '20261115.1249'; # VERSION | |||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use parent 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use BeamerReveal::Log; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 1 | my $store = undef; | |||||||||||
| 14 | |||||||||||||
| 15 | |||||||||||||
| 16 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 17 | 0 | my $class = shift; | |||||||||||
| 18 | |||||||||||||
| 19 | 0 | ▶ | $class = (ref $class ? ref $class : $class ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 0 | my $self = {}; | |||||||||||
| 21 | 0 | bless $self, $class; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||
| 28 | 0 | my ( $library, $fileName ) = @_; | |||||||||||
| 29 | |||||||||||||
| 30 | 0 | my $key = $library . '/' . $fileName; | |||||||||||
| 31 | 0 | ▶ | $store->{$key} = _readTemplate( $library, $fileName ) unless( exists $store->{$key} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 0 | return $store->{$key}; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | sub stampTemplate { | ||||||||||
|
Subroutine
stampTemplate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 37 | 0 | my ( $string, $hash ) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | while( my ( $stamp, $value ) = each %$hash ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 0 | ▶ | if ( defined( $value ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | sub _readTemplate { | ||||||||||
|
Subroutine
_readTemplate: not called CC=5 SCAR=34.0
| |||||||||||||
| 53 | 0 | my ( $library, $fileName ) = @_; | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | my $home = $^O eq 'MSWin32' ? $ENV{'userprofile'} : $ENV{'HOME'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 0 | ▶ | my $configDir = $ENV{'BEAMERREVEAL_CONFIG'} | ||||||||||
|
Condition0%0/2
$ENV{"BEAMERREVEAL_CONFIG"} // "$home/.config/BeamerReveal"
MC/DC0%0/1
$ENV{"BEAMERREVEAL_CONFIG"} // "$home/.config/BeamerReveal"
$ENV{"BEAMERREVEAL_CONFIG"}
Truth table0%0/2
A
A= $ENV{"BEAMERREVEAL_CONFIG"}
| |||||||||||||
| 57 | // "$home/.config/BeamerReveal"; | ||||||||||||
| 58 | 0 | my $templateFileName = "$configDir/templates/$library/$fileName"; | |||||||||||
| 59 | 0 | ▶ | $templateFileName = File::ShareDir::dist_dir( 'BeamerReveal' ) . "/templates/$library/$fileName" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | if ( ! -r $templateFileName ); | ||||||||||||
| 61 | |||||||||||||
| 62 | 0 | my $templateFile = IO::File->new(); | |||||||||||
| 63 | 0 | ▶ | $templateFile->open( "<$templateFileName" ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | or $BeamerReveal::Log::logger->fatal( "Error: installation incomplete - cannot find the template file '$fileName'" ); | ||||||||||||
| 65 | 0 | my $content = do { local $/; <$templateFile> }; | |||||||||||
| 66 | 0 | return $content; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | 1 | 1; | |||||||||||
| 71 | |||||||||||||
| 72 | __END__ | ||||||||||||