| 1 | package Sledge::Plugin::JSON::XS; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.00800; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 9 | 2 | our $ConformToRFC4627 = 0; | |||||||||||||||||||||||||||
| 10 | 2 | our $ENCODING = 'utf-8'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | my $pkg = caller(0); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | no strict 'refs'; ## no critic. | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | *{"$pkg\::output_json_xs"} = \&_output_json_xs; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | sub _output_json_xs { | ||||||||||||||||||||||||||
|
Subroutine
_output_json_xs: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 20 | 9 | my ($self, $src) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 9 | ▶ | my $content_type = | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->debug_level and $self->r->param("debug")
MC/DC100%2/2
$self->debug_level and $self->r->param("debug")
$self->debug_level
$self->r->param("debug")
Truth table100%3/3
A and B
A= $self->debug_levelB= $self->r->param("debug")
| |||||||||||||||||||||||||||||
| 23 | ( $self->debug_level && $self->r->param('debug') ) | ||||||||||||||||||||||||||||
| 24 | ? "text/plain; charset=$ENCODING" | ||||||||||||||||||||||||||||
| 25 | : _content_type($self, $ENCODING ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9 | my $json = encode_json($src); | |||||||||||||||||||||||||||
| 28 | 9 | ▶ | my $output = _add_callback($self, _validate_callback_param($self, ($self->r->param('callback') || '')), $json ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->r->param('callback') || ''
MC/DC100%1/1
$self->r->param('callback') || ''
$self->r->param('callback')
Truth table100%2/2
A
A= $self->r->param('callback')
| |||||||||||||||||||||||||||||
| 29 | 9 | $self->r->content_type($content_type); | |||||||||||||||||||||||||||
| 30 | 9 | $self->set_content_length(length $output); | |||||||||||||||||||||||||||
| 31 | 9 | $self->send_http_header; | |||||||||||||||||||||||||||
| 32 | 9 | $self->r->print($output); | |||||||||||||||||||||||||||
| 33 | 9 | $self->invoke_hook('AFTER_OUTPUT'); | |||||||||||||||||||||||||||
| 34 | 9 | $self->finished(1); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 8 | ▶ | sub _content_type { | ||||||||||||||||||||||||||
|
Subroutine
_content_type: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 38 | 8 | my ($self, $encoding) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 8 | my $user_agent = $self->r->header_in('User-Agent'); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | if ( $ConformToRFC4627 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 1 | return "application/json; charset=$encoding"; | |||||||||||||||||||||||||||
| 44 | ▶ | } elsif (($user_agent || '') =~ /Opera/) { | |||||||||||||||||||||||||||
|
Condition100%2/2
$user_agent || ''
MC/DC100%1/1
$user_agent || ''
$user_agent
Truth table100%2/2
A
A= $user_agent
| |||||||||||||||||||||||||||||
| 45 | 1 | return "application/x-javascript; charset=$encoding"; | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 6 | return "application/javascript; charset=$encoding"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 9 | ▶ | sub _add_callback { | ||||||||||||||||||||||||||
|
Subroutine
_add_callback: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 52 | 9 | my ($self, $cb, $json) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 9 | ▶ | if (Encode::is_utf8($cb)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | $cb = Encode::encode('utf8', $cb); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 9 | my $output; | |||||||||||||||||||||||||||
| 59 | 9 | ▶ | $output .= "$cb(" if $cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 9 | $output .= $json; | |||||||||||||||||||||||||||
| 61 | 9 | ▶ | $output .= ");" if $cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 9 | return $output; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 9 | ▶ | sub _validate_callback_param { | ||||||||||||||||||||||||||
|
Subroutine
_validate_callback_param: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 9 | my ($self, $param) = @_; | |||||||||||||||||||||||||||
| 68 | 9 | ▶ | return ( $param =~ /^[a-zA-Z0-9\.\_\[\]]+$/ ) ? $param : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | 1; | |||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||