| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Template::Recall::Base; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 25 | use strict; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 152 |  | 
| 4 | 4 |  |  | 4 |  | 21 | no warnings; | 
|  | 4 |  |  |  |  | 5 |  | 
|  | 4 |  |  |  |  | 1418 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION='0.08'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub render { | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 8 |  |  | 8 | 0 | 13 | my ( $class, $template, $hash_ref, $delims ) = @_; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 8 | 50 |  |  |  | 15 | if ( not defined ($template) ) { | 
| 15 | 0 |  |  |  |  | 0 | die "Template::Recall::Base::render() 'template' parameter not present"; | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 8 | 50 | 33 |  |  | 47 | my $user_delims = ref $delims && $#{$delims} == 1 ?  1 : 0; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 8 | 50 |  |  |  | 26 | if (ref $hash_ref) { | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 8 |  |  |  |  | 31 | while ( my ($key, $value) = each %$hash_ref) { | 
| 23 | 8 | 50 |  |  |  | 28 | if ( $user_delims ) { | 
| 24 | 8 |  |  |  |  | 27 | my $d = $delims->[0] . '\s*' . $key . '\s*' . $delims->[1]; | 
| 25 | 8 |  |  |  |  | 153 | $template =~ s/$d/$value/g; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | else { # exactly specified delims | 
| 28 | 0 |  |  |  |  | 0 | $template =~ s/$key/$value/g; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  | } # while | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | } # if | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # Do trimming, if so flagged | 
| 36 | 8 | 100 |  |  |  | 24 | return trim($class->{'trim'}, $template) if defined $class->{'trim'}; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 4 |  |  |  |  | 38 | return $template; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | } # render() | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | # Trim output if specified | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub trim { | 
| 48 | 4 |  |  | 4 | 0 | 6 | my ($trim, $template) = @_; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 4 | 50 |  |  |  | 9 | return $template if !defined($trim); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 4 | 100 | 66 |  |  | 18 | if ($trim eq 'left' or $trim eq 'l') { | 
| 53 | 1 |  |  |  |  | 4 | $template =~ s/^\s+//g; | 
| 54 | 1 |  |  |  |  | 5 | return $template; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 3 | 100 | 66 |  |  | 12 | if ($trim eq 'right' or $trim eq 'r') { | 
| 58 | 1 |  |  |  |  | 5 | $template =~ s/\s+$//g; | 
| 59 | 1 |  |  |  |  | 3 | return $template; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 2 | 50 | 33 |  |  | 11 | if ($trim eq 'both' or $trim eq 'b') { | 
| 63 | 2 |  |  |  |  | 8 | $template =~ s/^\s+|\s+$//g; | 
| 64 | 2 |  |  |  |  | 7 | return $template; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | } # trim() | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | 1; |