Salsa/Template.pm

filter: Statementstmt 31.1% 19 / 61 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 5 totaltotal 25.5% 23 / 90 CC 9 SCAR 29.0
CC
9
Cov
26%
replace
42.0
init
12.0
new
6.0
CRAP 18.1
« Salsa/Archive.pm ↑ Summary Salsa/Action/Return.pm »
1 #
2 # Mail/Salsa/Template.pm
3 # Last Modification: Sat Oct 29 20:23:23 WEST 2005
4 #
5 # Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>. All rights reserved.
6 # This module is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
8 #
9 package Mail::Salsa::Template;
10  
11 11 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 require Exporter;
16 11 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 11 our @ISA = qw(Exporter);
19  
20 # Items to export into callers namespace by default. Note: do not export
21 # names by default without a very good reason. Use EXPORT_OK instead.
22 # Do not simply export all your public functions/methods/constants.
23  
24 # This allows declaration use Mail::Salsa::Template ':all';
25 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
26 # will save memory.
27  
28 11 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
29 11 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30 11 our @EXPORT = qw();
31  
32 11 our $VERSION = '0.02';
33  
34 # Preloaded methods go here.
35  
36 # Autoload methods go after =cut, and are processed by the autosplit program.
37  
38 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my $proto = shift;
40 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
41 0 my $self = {
42 'lang' => "en",
43 'label' => "",
44 'outfh' => undef,
45 'infh' => undef,
46 @_,
47 };
48 0 bless ($self, $class);
49 0 $self->init();
50 0 return($self);
51 }
52  
53 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my $self = shift;
55  
56 0 my $label = $self->{'label'};
57 0 for(0..1) {
58 0 my $lang = uc($self->{'lang'});
59 0 my $module = "use Mail::Salsa::Lang::$lang qw(insidefh);\n";
60 0 eval($module);
61 0 ▶ ($@) ? ($self->{'lang'} = "en") : last;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
62 }
63 0 $self->{'infh'} = insidefh();
64 0 return();
65 }
66  
67 0 ▶sub filehandle {
Subroutine filehandle: not called CC=1 SCAR=6.9
Pod undocumented
68 0 my $self = shift;
69 0 $self->{'outfh'} = shift;
70 0 return();
71 }
72  
73 0 ▶sub label {
Subroutine label: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $self = shift;
75 0 $self->{'label'} = shift;
76 0 return();
77 }
78  
79 0 ▶sub replace {
Subroutine replace: not called CC=6 SCAR=37.4
Pod undocumented
80 0 my $self = shift;
81 0 my $vars = {@_};
82  
83 0 my $label = $self->{'label'};
84 0 my $infh = $self->{'infh'};
85 0 my $outfh = $self->{'outfh'};
86  
87 0 my $evalcode = "";
88 0 for my $key (keys(%{$vars})) {
89 0 my $val = $vars->{$key};
90 0 $val =~ s/\@/\\@/g;
91 0 $evalcode .= "s{\\\$$key\\b}{$val}g;\n";
92 }
93 0 my $msg = 0;
94 0 ▶ while(<$infh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $infh)) 0 0 0
95 0 ▶ if($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 0 0
96 0 ▶ last if(/^\<\/template\>[\n\r]+/);
Branch: 1 branch
BranchTrueFalseTotal
if m[^\</template\>[\n\r]+] 0 0 0
97 0 eval($evalcode);
98 0 s{^\.}{\.\.};
99 0 print $outfh $_;
100 0 next;
101 }
102 0 ▶ $msg = 1 if(/^\< *template +name=\"$label\" *\>[\n\r]+/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\< *template +name=\"$label\" *\>[\n\r]+/ 0 0 0
103 }
104 0 return();
105 }
106  
107 11 1;
108 __END__
« Salsa/Archive.pm ↑ Summary Salsa/Action/Return.pm »