line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
package CGI::ToXML; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#============================================================================= |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id: ToXML.pm,v 0.02 2002/02/05 01:09:18 mneylon Exp $ |
7
|
|
|
|
|
|
|
# $Revision: 0.02 $ |
8
|
|
|
|
|
|
|
# $Author: mneylon $ |
9
|
|
|
|
|
|
|
# $Date: 2002/02/05 01:09:18 $ |
10
|
|
|
|
|
|
|
# $Log: ToXML.pm,v $ |
11
|
|
|
|
|
|
|
# Revision 0.02 2002/02/05 01:09:18 mneylon |
12
|
|
|
|
|
|
|
# Slight fix in POD docs |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Revision 0.01 2002/02/03 17:11:44 mneylon |
15
|
|
|
|
|
|
|
# Initial release to Perlmonks |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
#============================================================================= |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
21635
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
21
|
1
|
|
|
1
|
|
1431
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
|
|
|
|
|
|
use Exporter (); |
25
|
|
|
|
|
|
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
26
|
|
|
|
|
|
|
$VERSION = sprintf( "%d.%02d", q( $Revision: 0.02 $ ) =~ /\s(\d+)\.(\d+)/ ); |
27
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
28
|
|
|
|
|
|
|
@EXPORT = qw(); |
29
|
|
|
|
|
|
|
@EXPORT_OK = qw( CGItoXML ); |
30
|
|
|
|
|
|
|
%EXPORT_TAGS = ( ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub CGItoXML { |
34
|
|
|
|
|
|
|
my ( $cgi, %options ) = @_; |
35
|
|
|
|
|
|
|
if ( ! $cgi->isa( "CGI" ) ) { |
36
|
|
|
|
|
|
|
warn "CGItoXML: Object isn't a CGI object, cannot convert"; |
37
|
|
|
|
|
|
|
return undef; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Determine which parameters we keep or not |
41
|
|
|
|
|
|
|
my @paramlist = $cgi->param; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Exclude what we can first... |
44
|
|
|
|
|
|
|
if ( exists $options{ exclude } ) { |
45
|
|
|
|
|
|
|
my %exclude_hash; $exclude_hash{ $_ }++ foreach @{ $options{ exclude } }; |
46
|
|
|
|
|
|
|
@paramlist = grep { !exists( $exclude_hash{ $_ } ) } @paramlist; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Include what we can... |
50
|
|
|
|
|
|
|
if ( exists $options{ include } ) { |
51
|
|
|
|
|
|
|
my %include_hash; $include_hash{ $_ }++ foreach @{ $options{ include } }; |
52
|
|
|
|
|
|
|
@paramlist = grep { exists( $include_hash{ $_ } ) } @paramlist; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Set up the hashes to be used for conversion |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my @params; |
58
|
|
|
|
|
|
|
foreach my $param ( @paramlist ) { |
59
|
|
|
|
|
|
|
my @values; |
60
|
|
|
|
|
|
|
# Ensure we get values as an array |
61
|
|
|
|
|
|
|
foreach my $value ( $cgi->param( $param ) ) { |
62
|
|
|
|
|
|
|
push @values, $value; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
push @params, { parameter => { name => $param, |
65
|
|
|
|
|
|
|
value => \@values } }; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %cgi_hash = ( cgi => { |
69
|
|
|
|
|
|
|
generator => "CGI::toXML", |
70
|
|
|
|
|
|
|
version => $VERSION, |
71
|
|
|
|
|
|
|
parameter => \@params } ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return XMLout( \%cgi_hash, rootname => undef ) ; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |