File Coverage

blib/lib/Geoffrey/Template.pm
Criterion Covered Total %
statement 42 42 100.0
branch 6 8 75.0
condition 6 8 75.0
subroutine 10 10 100.0
pod 4 4 100.0
total 68 72 94.4


line stmt bran cond sub pod time code
1             package Geoffrey::Template;
2              
3 4     4   368081 use utf8;
  4         10  
  4         176  
4 4     4   278 use 5.016;
  4         44  
5 4     4   51 use strict;
  4         7  
  4         109  
6 4     4   21 use warnings;
  4         9  
  4         2840  
7              
8             $Geoffrey::Template::VERSION = '0.000206';
9              
10             sub _handle_template {
11 9     9   16 my ( $self, $hr_template ) = @_;
12 9 100 100     25 if ( $hr_template->{template}
13 6         12 && scalar @{ $self->template( $hr_template->{template} ) } == 0 )
14             {
15 1         408 require Geoffrey::Exception::Template;
16 1         4 Geoffrey::Exception::Template::throw_template_not_found( $hr_template->{template} );
17             }
18 8         27 $self->_merge_templates( $hr_template->{name}, $hr_template->{template} );
19 8         14 push @{ $self->template( $hr_template->{name} ) }, $_ for @{ $hr_template->{columns} };
  8         17  
  13         23  
20 8         21 return 1;
21             }
22              
23             sub _merge_templates {
24 8     8   20 my ( $self, $s_destination_template, $s_source_template ) = @_;
25 8 100       18 return if !$s_source_template;
26             push
27 5         11 @{ $self->template($s_destination_template) },
28 5         8 @{ $self->template($s_source_template) };
  5         14  
29 5         10 return 1;
30             }
31              
32             sub new {
33 2     2 1 910 my $class = shift;
34 2         5 my $self = {@_};
35 2         6 $self->{templates} = {};
36 2         9 return bless $self, $class;
37             }
38              
39             sub template {
40 45     45 1 976 my ( $self, $s_template_name, $hr_template_value ) = @_;
41 45 50       96 return unless $s_template_name;
42 45   50     91 $self->templates->{$s_template_name} //= $hr_template_value // [];
      66        
43 45         90 return $self->templates->{$s_template_name};
44              
45             }
46              
47             sub templates {
48 90     90 1 141 my ( $self, $hr_templates ) = @_;
49 90 50       180 $self->{templates} = $hr_templates if $hr_templates;
50 90         467 return $self->{templates};
51             }
52              
53             sub load_templates {
54 3     3 1 1078 my ( $self, $ar_templates ) = @_;
55 3         5 $self->_handle_template($_) foreach @{$ar_templates};
  3         12  
56 2         9 return $self;
57             }
58              
59             1;
60              
61             __END__