| 1 | package Puzzle::Core; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.18'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use YAML qw(LoadFile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Puzzle::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Puzzle::DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Puzzle::Null; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use HTML::Mason::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Log::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Log::Any::Adapter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Params::Validate qw(:types); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use base 'Class::Container'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | __PACKAGE__->valid_params( | |||||||||||||||||||||||||||
| 21 | cfg_path => { parse => 'string', type => SCALAR}, | ||||||||||||||||||||||||||||
| 22 | session => { isa => 'Puzzle::Session', optional => 1 }, | ||||||||||||||||||||||||||||
| 23 | lang_manager => { isa => 'Puzzle::Lang::Manager' }, | ||||||||||||||||||||||||||||
| 24 | cfg => { isa => 'Puzzle::Config'} , | ||||||||||||||||||||||||||||
| 25 | tmpl => { isa => 'Puzzle::Template'} , | ||||||||||||||||||||||||||||
| 26 | dbg => { isa => 'Puzzle::Debug'} , | ||||||||||||||||||||||||||||
| 27 | args => { isa => 'Puzzle::Args'} , | ||||||||||||||||||||||||||||
| 28 | post => { isa => 'Puzzle::Post'} , | ||||||||||||||||||||||||||||
| 29 | sendmail => { isa => 'Puzzle::Sendmail'} , | ||||||||||||||||||||||||||||
| 30 | crud => { isa => 'Puzzle::DBIx::Crud'} , | ||||||||||||||||||||||||||||
| 31 | exception => { isa => 'Puzzle::Exception'} , | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | __PACKAGE__->contained_objects ( | |||||||||||||||||||||||||||
| 35 | session => {class => 'Puzzle::Session', delayed => 1}, | ||||||||||||||||||||||||||||
| 36 | lang_manager => 'Puzzle::Lang::Manager', | ||||||||||||||||||||||||||||
| 37 | cfg => 'Puzzle::Config', | ||||||||||||||||||||||||||||
| 38 | tmpl => 'Puzzle::Template', | ||||||||||||||||||||||||||||
| 39 | dbg => 'Puzzle::Debug', | ||||||||||||||||||||||||||||
| 40 | args => 'Puzzle::Args', | ||||||||||||||||||||||||||||
| 41 | post => 'Puzzle::Post', | ||||||||||||||||||||||||||||
| 42 | page => {class => 'Puzzle::Page', delayed => 1}, | ||||||||||||||||||||||||||||
| 43 | sendmail => 'Puzzle::Sendmail', | ||||||||||||||||||||||||||||
| 44 | crud => 'Puzzle::DBIx::Crud', | ||||||||||||||||||||||||||||
| 45 | exception => 'Puzzle::Exception', | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # all new valid_params are read&write methods | ||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use HTML::Mason::MethodMaker( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | read_only => [ qw(cfg_path dbh tmpl lang_manager lang dbg args page | ||||||||||||||||||||||||||||
| 52 | sendmail post exception crud) ], | ||||||||||||||||||||||||||||
| 53 | read_write => [ | ||||||||||||||||||||||||||||
| 54 | [ cfg => __PACKAGE__->validation_spec->{'cfg'} ], | ||||||||||||||||||||||||||||
| 55 | 1 | [ session => __PACKAGE__->validation_spec->{'session'} ], | |||||||||||||||||||||||||||
| 56 | [ error => { parse => 'string', type => SCALAR} ], | ||||||||||||||||||||||||||||
| 57 | ] | ||||||||||||||||||||||||||||
| 58 | 1 | ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | *db = \&dbh; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 64 | # append parameters required for new contained objects loading them | ||||||||||||||||||||||||||||
| 65 | # from YAML config file | ||||||||||||||||||||||||||||
| 66 | 0 | my $cfgH = LoadFile($_[1]); | |||||||||||||||||||||||||||
| 67 | 0 | my @params = qw(frames base frame_bottom_file frame_left_file frame_top_file exception_file | |||||||||||||||||||||||||||
| 68 | frame_right_file gids login description keywords db | ||||||||||||||||||||||||||||
| 69 | namespace debug debug_path cache auth_class traslation mail page); | ||||||||||||||||||||||||||||
| 70 | 0 | foreach (@params){ | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | push @_, ($_, $cfgH->{$_}) if (exists $cfgH->{$_}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | # initialize class and their contained objects | ||||||||||||||||||||||||||||
| 74 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 75 | 0 | $self->_init; | |||||||||||||||||||||||||||
| 76 | 0 | return $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($self->cfg->debug_path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | Log::Any::Adapter->set(File => $self->cfg->debug_path); | |||||||||||||||||||||||||||
| 85 | 0 | $self->{log} = Log::Any->get_logger(); | |||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 0 | $self->{log} = Puzzle::Null->new; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | # inizializzazione classi delayed | ||||||||||||||||||||||||||||
| 90 | 0 | my $center_class = 'Puzzle::Block'; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($self->cfg->page) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $center_class = $self->cfg->page->{center} if (exists $self->cfg->page->{center}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 0 | $self->{page} = $self->create_delayed_object('page',center_class => $center_class); | |||||||||||||||||||||||||||
| 95 | 0 | $self->_autohandler_once; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub _autohandler_once { | ||||||||||||||||||||||||||
|
Subroutine
_autohandler_once: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 0 | my $session_class = 'Puzzle::Session::Fake'; | |||||||||||||||||||||||||||
| 101 | 0 | $Apache::Request::Redirect::LOG = 0; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($self->cfg->db->{enabled}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | $Apache::Session::Store::DBI::TableName = $self->cfg->db->{session_table}; | |||||||||||||||||||||||||||
| 104 | my $dbi = 'dbi:mysql:database=' . $self->cfg->db->{name} . | ||||||||||||||||||||||||||||
| 105 | 0 | ';host=' . $self->cfg->db->{host}; | |||||||||||||||||||||||||||
| 106 | $self->{dbh} ||= new Puzzle::DBI($dbi,$self->cfg->db->{username}, | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $self->cfg->db->{password}, $self->cfg->db->{schema}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"dbh"} ||= "Puzzle::DBI"->new($dbi, $self->cfg->db->{"username"}, $self->cfg->db->{"password"}, $self->cfg->db->{"schema"})
MC/DC0%0/2
$self->{"dbh"} ||= "Puzzle::DBI"->new($dbi, $self->cfg->db->{"username"}, $self->cfg->db->{"password"}, $self->cfg->db->{"schema"})
$self->{"dbh"}
"Puzzle::DBI"->new($dbi, $self->cfg->db->{"username"}, $self->cfg->db->{"password"}, $self->cfg->db->{"schema"})
Truth table0%0/3
A ||= B
A= $self->{"dbh"}B= "Puzzle::DBI"->new($dbi, $self->cfg->db->{"username"}, $self->cfg->db->{"password"}, $self->cfg->db->{"schema"})
| |||||||||||||||||||||||||||||
| 108 | 0 | $session_class = 'Puzzle::Session'; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | # alter session class | ||||||||||||||||||||||||||||
| 111 | 0 | $self->{container}->{contained}->{session}->{class} = $session_class; | |||||||||||||||||||||||||||
| 112 | 0 | $self->{session} = $self->create_delayed_object('session'); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub process_request{ | ||||||||||||||||||||||||||
|
Subroutine
process_request: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | 0 | my $html; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | local $Puzzle::Core::instance = $self; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | &_mason->apache_req->no_cache(1); | |||||||||||||||||||||||||||
| 122 | 0 | $self->post->clear; | |||||||||||||||||||||||||||
| 123 | 0 | $self->args->clear; | |||||||||||||||||||||||||||
| 124 | 0 | $self->post->_set({$self->_mason->request_args}); | |||||||||||||||||||||||||||
| 125 | 0 | $self->session->load; | |||||||||||||||||||||||||||
| 126 | # enable always debug for debug users | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->cfg->debug(1) if $self->session->user->isGid('debug'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $self->dbg->timer_reset if $self->cfg->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | # configure language object | ||||||||||||||||||||||||||||
| 130 | 0 | $self->{lang} = $self->lang_manager->get_lang_obj; | |||||||||||||||||||||||||||
| 131 | # and send to templates | ||||||||||||||||||||||||||||
| 132 | 0 | $self->args->lang($self->lang_manager->lang); | |||||||||||||||||||||||||||
| 133 | 0 | $self->_login_logout; | |||||||||||||||||||||||||||
| 134 | 0 | $self->page->process; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($self->page->center->direct_output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | #$self->log->debug(( caller(0) )[3] . ": Print page WITHOUT frames"); | ||||||||||||||||||||||||||||
| 137 | 0 | $html = $self->page->center->html; | |||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||
| 139 | #$self->log->debug(( caller(0) )[3] . ": Print page with frames"); | ||||||||||||||||||||||||||||
| 140 | my $args = { | ||||||||||||||||||||||||||||
| 141 | frame_bottom => $self->page->bottom->body, | ||||||||||||||||||||||||||||
| 142 | frame_left => $self->page->left->body, | ||||||||||||||||||||||||||||
| 143 | frame_top => $self->page->top->body, | ||||||||||||||||||||||||||||
| 144 | frame_right => $self->page->right->body, | ||||||||||||||||||||||||||||
| 145 | frame_center => $self->page->body, | ||||||||||||||||||||||||||||
| 146 | header_client => $self->page->headers, | ||||||||||||||||||||||||||||
| 147 | body_attributes => $self->page->body_attributes, | ||||||||||||||||||||||||||||
| 148 | 0 | %{$self->dbg->all_mason_args}, | |||||||||||||||||||||||||||
| 149 | }; | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $args->{frame_debug} = $self->dbg->sprint if ($self->cfg->debug); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | $self->tmpl->autoDeleteHeader(0); | |||||||||||||||||||||||||||
| 152 | 0 | $html = $self->tmpl->html($args,$self->cfg->base); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 0 | print $html; | |||||||||||||||||||||||||||
| 155 | 0 | $self->session->save; | |||||||||||||||||||||||||||
| 156 | $self->dbh->storage->disconnect if ($self->cfg->db->{enabled} | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | && !$self->cfg->db->{persistent_connection}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->cfg->db->{"enabled"} and not $self->cfg->db->{"persistent_connection"}
MC/DC0%0/2
$self->cfg->db->{"enabled"} and not $self->cfg->db->{"persistent_connection"}
$self->cfg->db->{"enabled"}
not $self->cfg->db->{"persistent_connection"}
Truth table0%0/3
A and not(B)
A= $self->cfg->db->{"enabled"}B= not $self->cfg->db->{"persistent_connection"}
| |||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _login_logout { | ||||||||||||||||||||||||||
|
Subroutine
_login_logout: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ($self->post->logout) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 163 | 0 | $self->session->auth->logout; | |||||||||||||||||||||||||||
| 164 | ▶ | } elsif ($self->post->user ne '' && $self->post->pass ne '') { | |||||||||||||||||||||||||||
|
Condition0%0/3
$self->post->user ne "" and $self->post->pass ne ""
MC/DC0%0/2
$self->post->user ne "" and $self->post->pass ne ""
$self->post->user ne ""
$self->post->pass ne ""
Truth table0%0/3
A and B
A= $self->post->user ne ""B= $self->post->pass ne ""
| |||||||||||||||||||||||||||||
| 165 | 0 | $self->session->auth->login($self->post->user, $self->post->pass); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub _mason { | ||||||||||||||||||||||||||
|
Subroutine
_mason: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 170 | 0 | return HTML::Mason::Request->instance(); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 174 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 175 | 0 | return $s->{log}; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | 1; | |||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||