File Coverage

blib/lib/EJS/Template/Base.pm
Criterion Covered Total %
statement 22 23 95.6
branch 2 4 50.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 33 37 89.1


line stmt bran cond sub pod time code
1 8     8   136 use 5.006;
  8         28  
2 8     8   42 use strict;
  8         15  
  8         188  
3 8     8   39 use warnings;
  8         33  
  8         345  
4              
5             =head1 NAME
6              
7             EJS::Template::Base - Base class for some EJS::Template classes to hold common config
8              
9             =cut
10              
11             package EJS::Template::Base;
12              
13 8     8   46 use Scalar::Util qw(reftype);
  8         14  
  8         2089  
14              
15             =head1 Methods
16              
17             =head2 new
18              
19             Common constructor with the config
20              
21             =cut
22              
23             sub new {
24 274     274 1 589 my ($class, $config) = @_;
25 274 50       647 $config = {} unless ref $config;
26 274         523 $config = {map {$_ => $config->{$_}} @EJS::Template::CONFIG_KEYS};
  548         1502  
27 274         1561 return bless {config => $config}, $class;
28             }
29              
30             =head2 config
31              
32             Retrieves the config value.
33              
34             =cut
35              
36             sub config {
37 166     166 1 285 my $self = shift;
38 166         285 my $config = $self->{config};
39            
40 166         397 for my $name (@_) {
41 83 50 50     397 if ((reftype($config) || '') eq 'HASH') {
42 83         211 $config = $config->{$name};
43             } else {
44 0         0 return undef;
45             }
46             }
47            
48 166         872 return $config;
49             }
50              
51             =head1 SEE ALSO
52              
53             =over 4
54              
55             =item * L
56              
57             =back
58              
59             =cut
60              
61             1;