MPMinus/Debug/System.pm untested

filter: Statementstmt 0.0% 0 / 98 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 14 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 158 SCAR 52.0
CC
13
Cov
0%
controllers_info
42.0
metadata_info
20.0
config_info
12.0
CRAP 182.0
1 package MPMinus::Debug::System; # $Id: System.pm 173 2013-07-12 11:16:43Z minus $
2 use strict;
3
4 =head1 NAME
5
6 MPMinus::Debug::System - Debug functions
7
8 =head1 VERSION
9
10 Version 1.13
11
12 =head1 SYNOPSIS
13
14 use MPMinus::Debug::System;
15
16 =head1 DESCRIPTION
17
18 Debug functions. See C<Kernel.pm> of yuor project
19
20 =head1 FUNCTIONS
21
22 =over 8
23
24 =item B<typeglobs_info>
25
26 my %info = typeglobs_info( $namespace );
27
28 Returns list of defined typeglobs by $namespace
29
30 =item B<callstack_info>
31
32 my %info = callstack_info();
33
34 Returns Call stack
35
36 =item B<isa_info>
37
38 my %info = isa_info( $namespace );
39
40 Returns ISA contents by $namespace
41
42 =item B<env_info>
43
44 my %info = env_info();
45
46 Returns %ENV contents
47
48 =item B<config_info>
49
50 my %info = config_info( $m->get('conf') );
51
52 Returns configuration dump
53
54 =item B<metadata_info>
55
56 my %info = metadata_info( catfile($m->conf('document_root'), 'META.yml') );
57
58 Returns data from META.yml file of project
59
60 =item B<controllers_info>
61
62 my %info = controllers_info( $m->disp() );
63
64 Returns controllers information from dispatcher records
65
66 =back
67
68 =head1 AUTHOR
69
70 Serz Minus (Lepenkov Sergey) L<http://serzik.ru> E<lt>minus@mail333.comE<gt>
71
72 =head1 COPYRIGHT
73
74 Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved
75
76 =head1 LICENSE
77
78 This program is free software: you can redistribute it and/or modify
79 it under the terms of the GNU General Public License as published by
80 the Free Software Foundation, either version 3 of the License, or
81 (at your option) any later version.
82
83 This program is distributed in the hope that it will be useful,
84 but WITHOUT ANY WARRANTY; without even the implied warranty of
85 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86 GNU General Public License for more details.
87
88 See C<LICENSE> file
89
90 =cut
91
92 use vars qw($VERSION);
93 $VERSION = 1.13;
94
95 use base qw /Exporter/;
96 our @EXPORT = qw/
97 typeglobs_info
98 callstack_info
99 isa_info
100 env_info
101 config_info
102 metadata_info
103 controllers_info
104 /;
105
106 use Data::Dumper;
107 use YAML;
108 use Try::Tiny;
109
110 sub typeglobs_info {
111 my $f = shift || 'main';
112 no strict "refs";
113 my %outh;
114
115 foreach (sort keys %{"$f\:\:"}) {
116 my $k = $_;
117 $k =~ s/</&lt;/;
118 $k =~ s/>/&gt;/;
119 my $v = ${"$f\:\:"}{$_};
120 $v =~ s/</&lt;/;
121 $v =~ s/>/&gt;/;
122 $outh{$k} = $v if /^\w/;
123 }
124
125 return %outh
126 }
127 sub callstack_info {
128 my %outh;
129 my $j = 0;
130 my @args;
131
132 while (@args = caller($j++)) {
133 $outh{'#'.$j} = join("\n",map {$_ = defined($_) ? $_ : ''} @args[0..3]);
134 }
135
136 return %outh
137 }
138 sub isa_info {
139 my $package = shift || 'main';
140 my %outh;
141 my $j = 0;
142 no strict 'refs';
143 foreach (@{"$package\:\:ISA"}) {
144 $outh{'#'.(++$j)} = $_;
145 }
146 return %outh;
147 }
148 sub env_info {
149 my %outh;
150 my $val;
151 foreach my $var (sort(keys(%ENV))) {
152 $val = $ENV{$var};
153 $val =~ s|\n|\\n|g;
154 $val =~ s|"|\\"|g;
155 $outh{$var} = $val;
156 }
157 return %outh;
158 }
159 sub config_info {
160 my $lconf = shift || return ();
161 my %outh;
162
163 my %conf = %{$lconf};
164 foreach my $k (keys %conf) {
165 my $v = $conf{$k};
166
167 if (defined($v) && ref($v) eq "ARRAY") {
168 $outh{$k} = "[ " . (join ", ", @{$v}) . " ]";
169 } else {
170 $outh{$k} = defined($v) ? $v : '';
171 }
172 }
173 return %outh;
174 }
175 sub metadata_info {
176 my $metaf = shift || '';
177 my $meta = {Error => ""};
178 if (-e $metaf) {
179 try { $meta = YAML::LoadFile($metaf) } catch {$meta->{Error} = $_};
180 unless ($meta->{Error}) {
181 $meta = {Error => "Can't load file \"$metaf\""} unless $meta->{x_mpminus};
182 }
183 } else {
184 $meta = {Error => "File \"$metaf\" not exists"};
185 }
186 return %$meta;
187 }
188 sub controllers_info {
189 my $dispo = shift;
190 my $records = $dispo->{records};
191 my %ret;
192 foreach my $k (grep {$_ ne 'default'} keys %$records) {
193 my $rec = $dispo->get($k);
194 my $ctp = $rec->{type};
195 if ($ctp eq 'location') {
196 if ($k eq '/') {
197 $ret{'location:root'} = $k;
198 } else {
199 $ret{'location:'.$k} = $k;
200 }
201 } else {
202 my $params = $rec->{params};
203 my $paramsv = $params->{$ctp} ? $params->{$ctp} : 'undefined';
204 my $v = $paramsv && ref($paramsv) eq 'ARRAY' ? $paramsv->[0] : $paramsv;
205 $ret{lc($ctp.':'.$k)} = ref($v) ? "/$k" : $v;
206 }
207 }
208 return %ret;
209 }
210 1;