Setup/Templates.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 25 CC 3 SCAR 20.8
CC
3
Cov
0%
templater
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 8.0
1 #!/usr/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 package App::Module::Setup::Templates;
7  
8 our $VERSION = "0.02";
9  
10 sub templater {
11 my ( $text, $vars ) = @_;
12  
13 my %warned;
14 my $repl = sub {
15 my ( $key, $def ) = @_;
16 unless ( defined $vars->{$key} ) {
17 warn( "Template ", $vars->{" file"},
18 ": No replacement text for $key\n" )
19 unless $warned{$vars->{" file"} . $key}++;
20 return $def;
21 }
22 $vars->{$key};
23 };
24  
25 $text =~ s/(\[\%\s*(.*?)\s*\%\])/$repl->($2, $1)/ge;
26  
27 $text;
28 }
29  
30 1;