Type.pm

filter: Statementstmt 100% 112 / 112 Branchbran 88.8% 16 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 30 / 30 Podpod 100% 1 / 1 totaltotal 98.7% 159 / 161 CC 10 SCAR 5.2
CC
10
Cov
98%
__ANON__
4.0
_pack_q
3.0
_l2n
2.1
CRAP 1.7
« Client.pm ↑ Summary
1 package Hessian::Tiny::Type;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use fields qw(data type len class);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Hessian::Tiny::Type - Hessian Types & utility routines
12  
13 =head1 SUBROUTINES/METHODS
14  
15 =head2 new
16  
17 base class for other types
18  
19 =cut
20  
21 104 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
22 104 my($class,@params) = @_;
23 104 ▶ my $self = 1 == scalar @params
Branch: 1 branch
BranchTrueFalseTotal
1 == scalar @params ? : 39 65 104
24 ? {data=>$params[0]}
25 : {@params}
26 ;
27 104 return bless $self, $class;
28 }
29  
30 # Hessian 1.0 Types
31 3 ▶{ package Hessian::Type::Null; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶{ package Hessian::Type::True; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶{ package Hessian::Type::False; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶{ package Hessian::Type::Date; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶{ package Hessian::Type::Integer; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶{ package Hessian::Type::Long; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶{ package Hessian::Type::Binary; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶{ package Hessian::Type::String; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶{ package Hessian::Type::XML; use base 'Hessian::Tiny::Type'; } # 1.0 only
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶{ package Hessian::Type::Double; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶{ package Hessian::Type::List; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 ▶{ package Hessian::Type::Map; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
43 3 ▶{ package Hessian::Type::Header; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
44 3 ▶{ package Hessian::Type::Remote; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶{ package Hessian::Type::Fault; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 # Hessian 2.0 Types
48 3 ▶{ package Hessian::Type::Class; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
49 3 ▶{ package Hessian::Type::Object; use base 'Hessian::Tiny::Type'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 # helper functions for Convertor use
52 3 ▶sub _pack_q { # pack (64-bit) signed long
Subroutine _pack_q: called CC=3 SCAR=11.0
53 21 my $bi = shift;
54 21 ▶ $bi = Math::BigInt->new($bi) unless length(ref $bi) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless length ref $bi > 0 0 21 21
55 21 ▶ $bi = Math::BigInt->new('0x8000000000000000')->bmul(2)->badd($bi) if $bi->is_neg;
Branch: 1 branch
BranchTrueFalseTotal
if $bi->is_neg 8 13 21
56 21 return pack 'H16', sprintf '%016s',substr($bi->as_hex, 2);
57 }
58 42 ▶sub _unpack_q { # unpack (64-bit) signed long
Subroutine _unpack_q: called CC=2 SCAR=6.9
59 42 my $bytes = shift;
60 42 my $n = Math::BigInt->new('0x' . unpack('H16',$bytes));
61 42 my $m = Math::BigInt->new('0x7fffffffffffffff');
62 42 ▶ $n = Math::BigInt->new('0x8000000000000000')->bmul(-2)->badd($n) if $n->bcmp($m) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->bcmp($m) > 0 16 26 42
63 42 return $n;
64 }
65 #local to network order (and back)
66 87 ▶sub _l2n { return $Config{'byteorder'} =~ /^1234/ ? scalar reverse $_[0] : $_[0] }
Subroutine _l2n: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$Hessian::Tiny::Type::Config{'byteorder'} =~ /^1234/ ? : 87 0 87
67  
68 183 ▶sub _make_reader {
Subroutine _make_reader: called CC=1 SCAR=0.0
69 183 my $fh = shift;
70 183 binmode $fh, ':bytes';
71 585 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
72 585 my($len,$utf8_flag) = @_;
73 585 ▶ binmode $fh, $utf8_flag ? ':utf8' : ':bytes';
Branch: 1 branch
BranchTrueFalseTotal
$utf8_flag ? : 18 567 585
74 585 ▶ return seek $fh, $len, 1 if $len < 0; #rewind on negative len
Branch: 1 branch
BranchTrueFalseTotal
if $len < 0 39 546 585
75  
76 546 my $buf = '';
77 546 my $l = read $fh, $buf, $len;
78 546 ▶ die "_reader: want $len but got $l" unless $len == $l;
Branch: 1 branch
BranchTrueFalseTotal
unless $len == $l 2 544 546
79 544 return $buf;
80 }
81 183 }
82 183 ▶sub _make_writer {
Subroutine _make_writer: called CC=1 SCAR=0.0
83 183 my $fh = shift;
84 806 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
85 806 my($buf,$utf8_flag) = @_;
86 806 ▶ binmode $fh, $utf8_flag ? ':utf8' : ':bytes';
Branch: 1 branch
BranchTrueFalseTotal
$utf8_flag ? : 189 617 806
87 806 print $fh $buf;
88 }
89 183 }
90  
91 3 1; # End of Hessian::Type
« Client.pm ↑ Summary