blib/lib/NTS/Utils.pm

filter: Statementstmt 21.6% 8 / 37 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 20.0% 11 / 55 CC 10 SCAR 45.2
CC
10
Cov
16%
getForm
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 91.8
↑ Summary
1 # $Id: Utils.pm,v 1.2 2003/05/17 14:30:40 devel Exp $
2  
3 package NTS::Utils;
4  
5 #use 5.008;
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '2.0';
10  
11 # Recupega Post com multiples values
12 0 ▶sub getForm {
Subroutine getForm: not called CC=10 SCAR=47.0
Pod documented
13 0 my($i,@j,$k,%r,$c,%concat);
14
15 0 my $r = Apache->request;
16 0 $c = shift;
17 0 $i = $c;
18  
19 0 ▶ return () unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
20 0 ▶ while ($i =~ s/^\&?([a-zA-Z0-9-_\%\.\,\+]+)=([a-zA-Z0-9-_\*\@\%\.\,\+\/]+)?&?//sx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ s[^\&?([a-zA-Z0-9-_\%\.\,\+]+)=([a-zA-Z0-9-_\*\@\%\.\,\+/]+)?&?][]sx) 0 0 0
21 0 $j[0] = $1;
22 0 $j[1] = $2;
23  
24 # Trasnforma os chars especiais em normais
25 0 $j[0] =~ tr/+/ /;
26 0 $j[0] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
27
28 0 ▶ if (defined $j[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $j[1]) 0 0 0
29 0 $j[1] =~ tr/+/ /;
30 0 $j[1] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
31 }
32  
33 # Verifica quantas vezes se repete
34 0 $k = $c =~ s/(^|&)($j[0]=)/$1$2/gi;
35  
36 # Verifica se joga em array ou hash
37 0 ▶ if ($k > 1) { push (@{$r{$j[0]}},$j[1]); }
Branch: 1 branch
BranchTrueFalseTotal
if ($k > 1) { } 0 0 0
38 0 else { $r{$j[0]} = $j[1] }
39  
40 # Verifica se deve fazer concat
41 0 ▶ $concat{$1}->{$2} = $j[1] if ($j[0] =~ /^concat\.(.*)\.([0-9]+)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $j[0] =~ /^concat\.(.*)\.([0-9]+)$/ 0 0 0
42  
43 0 $k = 0;
44 }
45  
46 # Retorna dados do concat corretos
47 0 foreach $i (keys %concat) {
48 0 undef $r{$i};
49 0 foreach (sort keys %{$concat{$i}}) {
50 0 ▶ $r{$i} .= $concat{$i}->{$_} if $concat{$i}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $concat{$i}{$_} 0 0 0
51 }
52 }
53  
54 0 ▶ return %r if %r;
Branch: 1 branch
BranchTrueFalseTotal
if %r 0 0 0
55 0 return ();
56 }
57  
58 1 1;
59 #__END__
60  
61 =head1 NAME
62  
63 NTS::Utils - Utilitarios Web
64  
65 =head1 Description
66  
67 Funcoes simples e rapidas utilizadas em paginas CGI ou modperl
68  
69 =head1 SYNOPSIS
70  
71 use NTS::Utils;
72  
73 my %form = NTS::Utils::getForm(eval {my $i = $r->args || $r->content; return $i});
74  
75 $r->print($form{field});
76  
77 =head1 TO DO
78  
79 no comment
80  
81 =head1 DIRECTIVE
82  
83 =head2 getForm()
84  
85 %form = NTS::Utils::getForm(eval {my $i = $r->args || $r->content; return $i});
86  
87 =head1 Authors
88  
89 =over
90  
91 =item
92  
93 Udlei Nattis E<lt>unattis (at) nattis.comE<gt>
94  
95 =back
96  
97 =cut
98  
↑ Summary