Lite/Response.pm

filter: Statementstmt 88.3% 38 / 43 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 4 totaltotal 81.1% 56 / 69 CC 10 SCAR 13.0
CC
10
Cov
85%
param
5.8
_initialize
4.0
code
2.0
CRAP 3.7
« Lite.pm ↑ Summary
1 package Net::RRP::Lite::Response;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
6 1 my($class, $raw_data) = @_;
7 1 my $self = bless {
8 _code => 0,
9 _message => '',
10 _param => {},
11 }, $class;
12 1 $self->_initialize($raw_data);
13 1 return $self;
14 }
15  
16 1 ▶sub _initialize {
Subroutine _initialize: called CC=4 SCAR=14.0
17 1 my($self, $raw_data) = @_;
18 1 my @lines = split(/\r\n/, $raw_data);
19 1 my $status_line = shift @lines;
20 1 my($code, $message) = $status_line =~ m/^(\d+)\s+(.*)$/;
21 1 $self->code($code);
22 1 $self->message($message);
23 1 my %vars;
24 1 for my $line(@lines) {
25 10 my($key, $val) = split(/\s*:\s*/, $line, 2);
26 10 ▶ unless ($vars{lc($key)}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vars{lc $key}) { } 1 9 10
if (do { ref $vars{lc $key} eq 'ARRAY' }) { } 0 1 1
27 9 $vars{lc($key)} = $val
28 }
29 elsif (ref($vars{lc($key)}) eq 'ARRAY') {
30 0 push @{$vars{lc($key)}}, $val;
31 }
32 else{
33 1 $vars{lc($key)} = [ $vars{lc($key)} ];
34 1 push @{$vars{lc($key)}}, $val;
35 }
36 }
37 1 $self->{_param} = \%vars;
38 1 return $self;
39 }
40  
41 5 ▶sub param {
Subroutine param: called CC=5 SCAR=17.6
Pod undocumented
42 5 my $self = shift;
43 5 ▶ if (@_ == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 0 5 5
elsif (@_ == 1) { } 5 0 5
44 0 return keys %{$self->{_param}};
45 }
46 elsif (@_ == 1) {
47 5 my $key = lc($_[0]);
48 5 $key =~ s/_/ /g;
49 5 ▶ if (ref($self->{_param}->{$key}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_param"}{$key} eq "ARRAY") 1 4 5
50 1 ▶ return wantarray ? @{$self->{_param}->{$key}} : $self->{_param}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
51 }
52 4 return $self->{_param}->{$key};
53 }
54 else {
55 0 $self->{_param}->{$_[0]} = $_[1];
56 }
57 }
58  
59 2 ▶sub code {
Subroutine code: called CC=2 SCAR=6.9
Pod undocumented
60 2 my($self, $code) = @_;
61 2 ▶ $self->{_code} = $code if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 1 1 2
62 2 return $self->{_code};
63 }
64  
65 2 ▶sub message {
Subroutine message: called CC=2 SCAR=6.9
Pod undocumented
66 2 my($self, $message) = @_;
67 2 ▶ $self->{_message} = $message if $message;
Branch: 1 branch
BranchTrueFalseTotal
if $message 1 1 2
68 2 return $self->{_message};
69 }
70  
71 2 1;
72  
73 __END__
« Lite.pm ↑ Summary