line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Formatter::XML; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
29
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
190
|
|
4
|
8
|
|
|
8
|
|
25
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
171
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
24
|
use parent 'OAuth::Lite2::Formatter'; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
31
|
|
7
|
8
|
|
|
8
|
|
357
|
use Try::Tiny; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
309
|
|
8
|
8
|
|
|
8
|
|
6701
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Carp (); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub name { "xml" } |
12
|
|
|
|
|
|
|
sub type { "application/xml" } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub format { |
15
|
|
|
|
|
|
|
my ($self, $hash) = @_; |
16
|
|
|
|
|
|
|
my $xml = ''; |
17
|
|
|
|
|
|
|
$xml .= ''; |
18
|
|
|
|
|
|
|
for my $key ( keys %$hash ) { |
19
|
|
|
|
|
|
|
$xml .= sprintf(q{<%s>%s%s>}, |
20
|
|
|
|
|
|
|
$key, |
21
|
|
|
|
|
|
|
$hash->{$key}, |
22
|
|
|
|
|
|
|
$key); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
$xml .= ''; |
25
|
|
|
|
|
|
|
return $xml; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub parse { |
29
|
|
|
|
|
|
|
my ($self, $xml) = @_; |
30
|
|
|
|
|
|
|
my $parser = XML::LibXML->new; |
31
|
|
|
|
|
|
|
my $doc = $parser->parse_string($xml); |
32
|
|
|
|
|
|
|
my $root = $doc->documentElement(); |
33
|
|
|
|
|
|
|
Carp::croak " Element not found: " . $xml |
34
|
|
|
|
|
|
|
unless $root->nodeName eq 'OAuth'; |
35
|
|
|
|
|
|
|
my $hash = {}; |
36
|
|
|
|
|
|
|
my @children = $root->childNodes(); |
37
|
|
|
|
|
|
|
for my $child ( @children ) { |
38
|
|
|
|
|
|
|
next unless $child->nodeType == 1; |
39
|
|
|
|
|
|
|
my $key = $child->nodeName(); |
40
|
|
|
|
|
|
|
next unless $key; |
41
|
|
|
|
|
|
|
my $value = $child->textContent() || ''; |
42
|
|
|
|
|
|
|
$hash->{$key} = $value; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
return $hash; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
OAuth::Lite2::Formatter::XML - OAuth 2.0 XML formatters store |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $formatter = OAuth::Lite2::Formatter::XML->new; |
54
|
|
|
|
|
|
|
my $obj = $formatter->parse( $string ); |
55
|
|
|
|
|
|
|
$string = $formatter->format( $obj ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
DEPRECATED. |
60
|
|
|
|
|
|
|
OAuth 2.0 XML formatter. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 name |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Accessor for name of this format, "xml". |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 type |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Accessor for content-type of this format, "application/xml". |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 format( $object ) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $xml_string = $formatter->format( $obj ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 parse( $xml_string ) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $obj = $formatter->parse( $xml_string ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L |
83
|
|
|
|
|
|
|
L |
84
|
|
|
|
|
|
|
L |
85
|
|
|
|
|
|
|
L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Lyo Kato, Elyo.kato@gmail.comE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Copyright (C) 2010 by Lyo Kato |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
96
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
97
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |