MPMinus/Debug/Info.pm untested

filter: Statementstmt 0.0% 0 / 86 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 117 SCAR 40.3
CC
7
Cov
0%
mpminfo
20.0
_table_std
20.0
BEGIN
2.0
CRAP 56.0
1 package MPMinus::Debug::Info; # $Id: Info.pm 151 2013-05-29 14:31:19Z minus $
2 use strict;
3
4 =head1 NAME
5
6 MPMinus::Debug::Info - mpminfo methods
7
8 =head1 VERSION
9
10 Version 1.00
11
12 =head1 SYNOPSIS
13
14 sub record {
15 (
16 -uri => '/',
17 -response => sub { shift->mpminfo() },
18 )
19 }
20
21 =head1 DESCRIPTION
22
23 The main module provides debugging methods
24
25 =head1 METHODS
26
27 =over 8
28
29 =item B<mpminfo>
30
31 $m->mpminfo();
32 $m->mpminfo( $template_url );
33
34 Method mpminfo returns info page
35
36 =back
37
38 =head1 AUTHOR
39
40 Serz Minus (Lepenkov Sergey) L<http://serzik.ru> E<lt>minus@mail333.comE<gt>
41
42 =head1 COPYRIGHT
43
44 Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved
45
46 =head1 LICENSE
47
48 This program is free software: you can redistribute it and/or modify
49 it under the terms of the GNU General Public License as published by
50 the Free Software Foundation, either version 3 of the License, or
51 (at your option) any later version.
52
53 This program is distributed in the hope that it will be useful,
54 but WITHOUT ANY WARRANTY; without even the implied warranty of
55 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 GNU General Public License for more details.
57
58 See C<LICENSE> file
59
60 =cut
61
62 use vars qw($VERSION);
63 $VERSION = 1.00;
64
65 use Apache2::Const;
66 use CGI();
67 use CTK::Util qw/ :API /;
68 use TemplateM;
69 use Data::Dumper;
70 use MPMinus::Debug::System;
71
72 sub mpminfo {
73 my $m = shift;
74 my $url = shift;
75 my $r = $m->r;
76 my %h = ();
77 my $q = new CGI;
78 my %usr = ();
79 foreach ($q->all_parameters) {
80 $usr{$_} = $q->param($_);
81 Encode::_utf8_on($usr{$_});
82 }
83 my $urlshtml = $m->conf('url_shtml');
84 my $turl = $urlshtml.'/'.$m->conf('file_mpminfo');
85 my ($status, $password);
86 ($status, $password) = $r->get_basic_auth_pw if $r->user();
87 my $template = new TemplateM(
88 -url => $url || $turl,
89 -user => $r->user() || '',
90 -pass => defined($password) ? $password : '',
91 -utf8 => 1,
92 );
93
94 # STEP 1. GENERAL DATA
95 my $gcfg = $m->get_node('conf');
96 my $whoiam = $m->namespace();
97 $template->stash($gcfg);
98 $h{whoiam} = $whoiam;
99 $h{curpackage} = scalar(__PACKAGE__);
100 $h{localcount} = $m->conf('package')->[1];
101 $h{mobject} = Dumper($m);
102
103 # STEP 2. CONFIGURATION AND META DATA
104 _table_std($template, controllers => {controllers_info($m->disp())});
105 _table_std($template, cfgdata => {config_info($gcfg)});
106 _table_std($template, metadata => {metadata_info(catfile($m->conf('document_root'),'META.yml'))});
107
108 # STEP 4. TYPEGLOBS, CALLSTACK, ISA, ENVIRONMENTS (ENV, USR)
109 _table_std($template, typeglobs2 => {typeglobs_info($whoiam)});
110 _table_std($template, typeglobs1 => {typeglobs_info('MPM')});
111 _table_std($template, typeglobs0 => {typeglobs_info()});
112 _table_std($template, callstack => {callstack_info()});
113 _table_std($template, isa2 => {isa_info($whoiam.'::Index')});
114 _table_std($template, isa1 => {isa_info($whoiam.'::Handlers')});
115 _table_std($template, isa0 => {isa_info('MPMinus')});
116 _table_std($template, envdata => {env_info()});
117 _table_std($template, usrdata => \%usr);
118
119 # OUTPUT
120 $template->stash(\%h);
121 my $output = $template->output();
122 croak("Template \"$turl\" not found!") unless $output;
123 $r->content_type('text/html; charset=UTF-8');
124 my $len = length(Encode::encode_utf8($output)) || 0;
125 $r->headers_out->set('Content-Length', $len);
126 $r->print($output);
127 $r->rflush();
128 return Apache2::Const::OK;
129 }
130
131 sub _table_std {
132 my ($t,$block,$rhash) = @_;
133
134 my $cfg_box = $t->start($block);
135 foreach my $k (sort {$a cmp $b} keys %$rhash) {
136 my $v = defined($rhash->{$k}) ? $rhash->{$k} : '';
137 my $class = ($v =~ /^[+\-]?\d+$/) ? 'integer' : 'string';
138 $cfg_box->loop(
139 name => $k,
140 value => ref($v) ? Dumper($v) : $v,
141 class => $class,
142 );
143 }
144 $cfg_box->finish;
145 }
146
147 1;