| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # $Id$ | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package WebService::Simple::Parser::JSON; | 
| 4 | 3 |  |  | 3 |  | 13 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 79 |  | 
| 5 | 3 |  |  | 3 |  | 13 | use warnings; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 82 |  | 
| 6 | 3 |  |  | 3 |  | 14 | use base qw(WebService::Simple::Parser); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 635 |  | 
| 7 | 3 |  |  | 3 |  | 17 | use JSON 2.0; | 
|  | 3 |  |  |  |  | 80 |  | 
|  | 3 |  |  |  |  | 24 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub new | 
| 10 |  |  |  |  |  |  | { | 
| 11 | 4 |  |  | 4 | 1 | 6 | my $class = shift; | 
| 12 | 4 |  |  |  |  | 8 | my %args  = @_; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 4 |  | 33 |  |  | 67 | my $json  = delete $args{json} || JSON->new; | 
| 15 | 4 |  |  |  |  | 29 | my $self  = $class->SUPER::new(%args); | 
| 16 | 4 |  |  |  |  | 43 | $self->{json} = $json; | 
| 17 | 4 |  |  |  |  | 15 | return $self; | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub parse_request | 
| 21 |  |  |  |  |  |  | { | 
| 22 | 2 |  |  | 2 | 0 | 3 | my $self = shift; | 
| 23 |  |  |  |  |  |  | #   my $content = $_[0]->decoded_content; | 
| 24 |  |  |  |  |  |  | #   # JSONP to pure JSON | 
| 25 |  |  |  |  |  |  | #   $content =~ s/[a-zA-Z_\$][a-zA-Z0-9_\$]*\s*\((.+)\)\s*;?\s*$/$1/; | 
| 26 | 2 |  |  |  |  | 40 | $self->{json}->encode( $_[0] ); | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub parse_response | 
| 30 |  |  |  |  |  |  | { | 
| 31 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 32 | 0 |  |  |  |  |  | my $content = $_[0]->decoded_content; | 
| 33 |  |  |  |  |  |  | # JSONP to pure JSON | 
| 34 | 0 |  |  |  |  |  | $content =~ s/[a-zA-Z_\$][a-zA-Z0-9_\$]*\s*\((.+)\)\s*;?\s*$/$1/; | 
| 35 | 0 |  |  |  |  |  | $self->{json}->decode( $content ); | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | 1; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | __END__ |