GX/HTTP/Body/Stream.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 77.2% 17 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 100% 4 / 4 totaltotal 83.9% 73 / 87 CC 13 SCAR 14.3
CC
13
Cov
86%
__initialize
6.2
print_to
6.0
new
3.1
CRAP 4.2
« GX/Serializer/JSON.pm ↑ Summary GX/Meta/Delegator.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/HTTP/Body/Stream.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::HTTP::Body::Stream;
7  
8 3 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 # ----------------------------------------------------------------------------------------------------------------------
15 # Constants
16 # ----------------------------------------------------------------------------------------------------------------------
17  
18 3 ▶use constant BUFFER_SIZE => 8192;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 # ----------------------------------------------------------------------------------------------------------------------
22 # Class setup
23 # ----------------------------------------------------------------------------------------------------------------------
24  
25 3 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 3 extends 'GX::HTTP::Body';
28  
29 3 has 'source' => (
30 isa => 'Scalar',
31 accessor => { type => 'get' }
32 );
33  
34 3 build;
35  
36  
37 # ----------------------------------------------------------------------------------------------------------------------
38 # Constructor
39 # ----------------------------------------------------------------------------------------------------------------------
40  
41 17 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
42  
43 17 my $invocant = shift;
44  
45 17 ▶ return eval { $invocant->SUPER::new( ( @_ == 1 ) ? ( source => $_[0] ) : @_ ) } || complain $@;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 13 4 17
Condition33%1/3
eval { do { $invocant->SUPER::new(@_ == 1 ? ('source', $_[0]) : @_) } } || &complain($@)
l!l&&r!l&&!r
1700
MC/DC0%0/2
eval { do { $invocant->SUPER::new(@_ == 1 ? ('source', $_[0]) : @_) } } || &complain($@)
eval { do { $invocant->SUPER::new(@_ == 1 ? ('source', $_[0]) : @_) } } &complain($@)
Truth table33%1/3
A || B
A= eval { do { $invocant->SUPER::new(@_ == 1 ? ('source', $_[0]) : @_) } }B= &complain($@)
ABresult
1X1
011
000
46  
47 }
48  
49  
50 # ----------------------------------------------------------------------------------------------------------------------
51 # Public methods
52 # ----------------------------------------------------------------------------------------------------------------------
53  
54 0 ▶sub length {
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
55  
56 0 return -1;
57  
58 }
59  
60 10 ▶sub print_to {
Subroutine print_to: called CC=6 SCAR=18.0
Pod documented
61  
62 10 my $self = shift;
63 10 my $handle = shift;
64  
65 10 ▶ my $source = $self->source or return;
Branch: 1 branch
BranchTrueFalseTotal
my $source = $self->source or return 10 0 10
66  
67 10 my $result;
68  
69 10 ▶ if ( ref $source eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $source eq 'CODE') { } 6 4 10
70  
71 6 while ( 1 ) {
72 66 ▶ $result = $source->( $handle ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$result = &$source($handle) or last 60 6 66
73 }
74  
75 }
76 else {
77  
78 4 ▶ while ( $result = $source->read( my $buffer, BUFFER_SIZE ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result = $source->read(my $buffer, 8192)) 52 4 56
79 52 ▶ $handle->print( $buffer ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$handle->print($buffer) or return 52 0 52
80 }
81  
82 }
83  
84 10 return defined $result;
85  
86 }
87  
88 0 ▶sub readonly {
Subroutine readonly: not called CC=1 SCAR=6.9
Pod documented
89  
90 0 return 1;
91  
92 }
93  
94  
95 # ----------------------------------------------------------------------------------------------------------------------
96 # Internal methods
97 # ----------------------------------------------------------------------------------------------------------------------
98  
99 17 ▶sub __initialize {
Subroutine __initialize: called CC=6 SCAR=18.3
100  
101 17 my $self = shift;
102 17 my $args = shift;
103  
104 17 ▶ if ( exists $args->{'source'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"source"}) 17 0 17
105  
106 17 ▶ if ( defined $args->{'source'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"source"}) 17 0 17
107  
108 17 ▶ if ( blessed $args->{'source'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($args->{'source'})) { } 2 15 17
elsif (ref $args->{'source'} eq 'CODE') { } 6 9 15
109 2 $self->{'source'} = $args->{'source'};
110 }
111 elsif ( ref $args->{'source'} eq 'CODE' ) {
112 6 $self->{'source'} = $args->{'source'};
113 }
114 else {
115 9 $self->{'source'} = eval { IO::Handle->new_from_fd( $args->{'source'}, '<' ) };
116 }
117  
118 }
119  
120 17 ▶ if ( ! $self->{'source'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"source"}) 0 17 17
121 0 throw "Invalid argument (\"source\")";
122 }
123  
124 }
125  
126 17 return;
127  
128 }
129  
130  
131 3 1;
132  
133 __END__
« GX/Serializer/JSON.pm ↑ Summary GX/Meta/Delegator.pm »