| 1 | package OAuth::Lite2::Formatter::XML; | ||||||||||||
| 2 | |||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 8 | ▶ | use parent 'OAuth::Lite2::Formatter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | ▶ | use Try::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 8 | ▶ | use XML::LibXML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 8 | ▶ | use Carp (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 9 | ▶ | sub name { "xml" } | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 12 | 9 | ▶ | sub type { "application/xml" } | ||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 13 | |||||||||||||
| 14 | sub format { | ||||||||||||
| 15 | 5 | ▶ | my ($self, $hash) = @_; | ||||||||||
|
Subroutine
format: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 16 | 5 | my $xml = '<?xml version="1.0" encoding="UTF-8"?>'; | |||||||||||
| 17 | 5 | $xml .= '<OAuth>'; | |||||||||||
| 18 | 5 | for my $key ( keys %$hash ) { | |||||||||||
| 19 | $xml .= sprintf(q{<%s>%s</%s>}, | ||||||||||||
| 20 | $key, | ||||||||||||
| 21 | 20 | $hash->{$key}, | |||||||||||
| 22 | $key); | ||||||||||||
| 23 | } | ||||||||||||
| 24 | 5 | $xml .= '</OAuth>'; | |||||||||||
| 25 | 5 | return $xml; | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | sub parse { | ||||||||||||
| 29 | 2 | ▶ | my ($self, $xml) = @_; | ||||||||||
|
Subroutine
parse: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||
| 30 | 2 | my $parser = XML::LibXML->new; | |||||||||||
| 31 | 2 | my $doc = $parser->parse_string($xml); | |||||||||||
| 32 | 1 | my $root = $doc->documentElement(); | |||||||||||
| 33 | 1 | ▶ | Carp::croak "<OAuth/> Element not found: " . $xml | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | unless $root->nodeName eq 'OAuth'; | ||||||||||||
| 35 | 1 | my $hash = {}; | |||||||||||
| 36 | 1 | my @children = $root->childNodes(); | |||||||||||
| 37 | 1 | for my $child ( @children ) { | |||||||||||
| 38 | 4 | ▶ | next unless $child->nodeType == 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 4 | my $key = $child->nodeName(); | |||||||||||
| 40 | 4 | ▶ | next unless $key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 4 | ▶ | my $value = $child->textContent() || ''; | ||||||||||
|
Condition50%1/2
$child->textContent || ''
MC/DC0%0/1
$child->textContent || ''
$child->textContent
Truth table50%1/2
A
A= $child->textContent
| |||||||||||||
| 42 | 4 | $hash->{$key} = $value; | |||||||||||
| 43 | } | ||||||||||||
| 44 | 1 | 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<OAuth::Lite2::Formatter> | ||||||||||||
| 83 | L<OAuth::Lite2::Formatters> | ||||||||||||
| 84 | L<OAuth::Lite2::Formatter::JSON> | ||||||||||||
| 85 | L<OAuth::Lite2::Formatter::FormURLEncoded> | ||||||||||||
| 86 | |||||||||||||
| 87 | =head1 AUTHOR | ||||||||||||
| 88 | |||||||||||||
| 89 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||
| 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 | 8 | 1; | |||||||||||