Nes/Singleton.pm

filter: Statementstmt 82.4% 47 / 57 Branchbran 50.0% 5 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 71.4% 5 / 7 Podpod 60.0% 3 / 5 totaltotal 73.5% 64 / 87 CC 8 SCAR 15.8
CC
8
Cov
76%
new
7.1
start
6.0
add
2.0
CRAP 4.8
« Nes/Minimal/Misc.pm ↑ Summary Nes/DB.pm »
1 #!/usr/bin/perl
2  
3 # -----------------------------------------------------------------------------
4 #
5 # Nes by Skriptke
6 # Copyright 2009 - 2010 Enrique F. Castañón Barbero
7 # Licensed under the GNU GPL.
8 #
9 # CPAN:
10 # http://search.cpan.org/dist/Nes/
11 #
12 # Sample:
13 # http://nes.sourceforge.net/
14 #
15 # Repository:
16 # http://github.com/Skriptke/nes
17 #
18 # Version 1.03
19 #
20 # Singleton.pm
21 #
22 # -----------------------------------------------------------------------------
23  
24 {
25 package Nes::Singleton;
26
27 5 my $instance;
28  
29 4 ▶ sub new {
Subroutine new: called CC=7 SCAR=19.6
Pod documented
30 4 my $class = shift;
31 4 ▶ my $self = $instance || bless {}, $class;
Condition100%2/2
$instance || bless({}, $class)
l!l
22
MC/DC100%1/1
$instance || bless({}, $class)
$instance
Truth table100%2/2
A
A= $instance
Aresult
11
00
32 4 my ( $file ) = @_;
33
34 4 ▶ if ( $instance ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instance) { } 2 2 4
35 2 $self->{'container'} = nes_container->get_obj();
36 2 $self->{'this_template_name'} = $self->{'container'}->{'file_name'};
37 2 $self->{'top_template_name'} = $self->{'top_container'}->{'file'};
38 2 return $self;
39 } else {
40 2 $instance = $self;
41 }
42  
43 2 ▶ $self->{'file'} = $ENV{'PATH_TRANSLATED'} || $file;
Condition33%1/3
$ENV{'PATH_TRANSLATED'} || $file
l!l&&r!l&&!r
020
MC/DC0%0/2
$ENV{'PATH_TRANSLATED'} || $file
$ENV{'PATH_TRANSLATED'} $file
Truth table33%1/3
A || B
A= $ENV{'PATH_TRANSLATED'}B= $file
ABresult
1X1
011
000
44
45 2 my $dir = $self->{'file'};
46 2 $dir =~ s/[^\/]*$//;
47 2 chdir $dir;
48 5 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 $dir = getcwd;
50
51 2 ▶ die "No template defined: $@" if !$self->{'file'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"file"} 0 2 2
52  
53 2 $self->{'CFG'} = Nes::Setting->new();
54 2 $self->{'top_container'} = nes_top_container->new( $self->{'file'}, $dir );
55 2 $self->{'container'} = nes_container->get_obj();
56 2 $self->{'cookies'} = nes_cookie->get_obj();
57 2 $self->{'session'} = nes_session->get_obj();
58 2 $self->{'query'} = nes_query->get_obj();
59 2 $self->{'register'} = nes_register->get_obj();
60 2 $self->{'nes'} = $self->{'top_container'}->{'nes'};
61 2 $self->{'this_template_name'} = $self->{'container'}->{'file_name'};
62 2 $self->{'top_template_name'} = $self->{'top_container'}->{'file'};
63  
64 # todo, comprobar que existe el juego de caracteres antes
65 5 ▶ use POSIX qw(locale_h);
Subroutine BEGIN: called CC=1 SCAR=0.0
66 2 ▶ POSIX::setlocale(LC_ALL, "$self->{'CFG'}{'locale'}") if $self->{'CFG'}{'locale'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CFG"}{"locale"} 0 2 2
67
68 2 ▶ if ( $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 2 0 2
69 # todo, implementar emulación CGI para linea de comandos
70 # $ENV{REMOTE_ADDR} = '127.0.0.1' if !$ENV{REMOTE_ADDR};
71 2 $self->run();
72 2 exit;
73 }
74
75 0 return $self;
76 }
77  
78 2 ▶ sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
79 2 my $self = shift;
80  
81 2 $self->{'container'}->go();
82 2 $self->{'top_container'}->{'container'}->out();
83  
84 2 return;
85 }
86  
87 2 ▶ sub out {
Subroutine out: called CC=1 SCAR=0.0
Pod documented
88 2 my $self = shift;
89 2 my %tags;
90 2 (%tags) = @_;
91  
92 2 $self->{'container'}->set_tags(%tags);
93 2 $self->{'container'}->interpret();
94  
95 0 return;
96 }
97
98 0 ▶ sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
99 0 my $self = shift;
100 0 my %tags;
101 0 (%tags) = @_;
102  
103 0 $self->{'container'}->add_tags(%tags);
104  
105 0 return;
106 }
107
108 0 ▶ sub start {
Subroutine start: not called CC=2 SCAR=17.9
Pod undocumented
109 0 my $class = shift;
110
111 0 ▶ utl::cleanup(\$instance) if $ENV{'MOD_PERL'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MOD_PERL"} 0 0 0
112  
113 0 return $class->new();
114 }
115  
116 }
117  
118  
119 5 1;
« Nes/Minimal/Misc.pm ↑ Summary Nes/DB.pm »