IO/DelegationToken/Reader.pm

filter: Statementstmt 33.8% 24 / 71 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 23.9% 33 / 138 CC 22 SCAR 35.9
CC
22
Cov
21%
_read_vlong
72.0
parseTokenStorageStream
56.0
vlong
30.0
CRAP 36.3
↑ Summary IO/RCFile/Reader.pm »
1 package Hadoop::IO::DelegationToken::Reader;
2 1 $Hadoop::IO::DelegationToken::Reader::VERSION = '0.003';
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 TOKEN_STORAGE_MAGIC => 'HDTS',
10 TOKEN_STORAGE_VERSION => 0,
11 1 };
12  
13 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our @EXPORT_OK = qw(
18 parseTokenStorageStream
19 vlong
20 );
21  
22 1 our %EXPORT_TAGS = (
23 all => \@EXPORT_OK,
24 );
25  
26 0 ▶sub parseTokenStorageStream {
Subroutine parseTokenStorageStream: not called CC=7 SCAR=40.3
Pod documented
27 0 my ($fh) = @_;
28  
29 0 my $buf;
30 0 ▶ croak "Bad header found in token storage"
Branch: 1 branch
BranchTrueFalseTotal
if read $fh, $buf, 4 and $buf ne "HDTS" 0 0 0
Condition0%0/3
read $fh, $buf, 4 and $buf ne "HDTS"
!ll&&!rl&&r
000
MC/DC0%0/2
read $fh, $buf, 4 and $buf ne "HDTS"
read $fh, $buf, 4 $buf ne "HDTS"
Truth table0%0/3
A and B
A= read $fh, $buf, 4B= $buf ne "HDTS"
ABresult
0X0
100
111
31 if read( $fh, $buf, 4 ) && $buf ne TOKEN_STORAGE_MAGIC;
32 0 ▶ croak sprintf "Unknown version %d version in token storage", unpack( 'C', $buf )
Branch: 1 branch
BranchTrueFalseTotal
if read $fh, $buf, 1 and unpack("C", $buf) != 0 0 0 0
Condition0%0/3
read $fh, $buf, 1 and unpack("C", $buf) != 0
!ll&&!rl&&r
000
MC/DC0%0/2
read $fh, $buf, 1 and unpack("C", $buf) != 0
read $fh, $buf, 1 unpack("C", $buf) != 0
Truth table0%0/3
A and B
A= read $fh, $buf, 1B= unpack("C", $buf) != 0
ABresult
0X0
100
111
33 if read( $fh, $buf, 1 ) && unpack( 'C', $buf ) != TOKEN_STORAGE_VERSION;
34  
35 # read the tokens
36 0 my %token;
37 0 for ( 1 .. _read_vint( $fh ) ) {
38 0 read( $fh, my $alias, _read_vint($fh) );
39 0 read( $fh, my $identifier, _read_vint($fh) );
40 0 read( $fh, my $password, _read_vint($fh) );
41 0 read( $fh, my $kind, _read_vint($fh) );
42 0 read( $fh, my $service, _read_vint($fh) );
43 0 $token{$alias} = {
44 identifier => $identifier,
45 password => $password,
46 kind => $kind,
47 service => $service,
48 };
49 }
50  
51 # read the secrets
52 0 my %secret;
53 0 for ( 1 .. _read_vint( $fh ) ) {
54 0 read( $fh, my $alias, _read_vint($fh) );
55 0 read( $fh, my $secret, _read_vint($fh) );
56 0 $secret{$alias} = $secret;
57 }
58  
59 0 return { token => \%token, secret => \%secret };
60 }
61  
62 0 ▶sub _read_vint {
Subroutine _read_vint: not called CC=3 SCAR=24.8
63 0 my ($fh) = @_;
64 0 my $n = _read_vlong($fh);
65 0 ▶ if ( $n <= 2147483647 && $n >= -2147483648 ) { return $n; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= 2147483647 and $n >= -2147483648) { } 0 0 0
Condition0%0/3
$n <= 2147483647 and $n >= '-2147483648'
!ll&&!rl&&r
000
MC/DC0%0/2
$n <= 2147483647 and $n >= '-2147483648'
$n <= 2147483647 $n >= '-2147483648'
Truth table0%0/3
A and B
A= $n <= 2147483647B= $n >= '-2147483648'
ABresult
0X0
100
111
66 0 else { die "value too long to fit in integer"; }
67 }
68  
69 0 ▶sub _read_vlong {
Subroutine _read_vlong: not called CC=8 SCAR=42.8
70 0 my ($fh) = @_;
71 0 my $buf;
72  
73 # For -112 <= i <= 127, only one byte is used with the actual value.
74 # For other values of i, the first byte value indicates whether the
75 # long is positive or negative, and the number of bytes that follow.
76 # If the first byte value v is between -113 and -120, the following
77 # long is positive, with number of bytes that follow are -(v+112).
78 # If the first byte value v is between -121 and -128, the following
79 # long is negative, with number of bytes that follow are -(v+120).
80 # Bytes are stored in the high-non-zero-byte-first order.
81 #
82 # https://github.com/apache/hadoop/blob/branch-2.8.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java#L307
83  
84 # first byte of a vint/vlong to determine the number of bytes
85 0 ▶ read( $fh, $buf, 1 ) or die 'TODO';
Branch: 1 branch
BranchTrueFalseTotal
read $fh, $buf, 1 or die "TODO" 0 0 0
86 0 my $size = _decode_size($buf);
87 0 my $val = unpack( 'c', $buf );
88  
89 0 ▶ if ( $size == 1 ) { return $val; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 1) { } 0 0 0
90 else { # build the Java long from bytes
91 0 ▶ read( $fh, $buf, $size ) or die 'TODO';
Branch: 1 branch
BranchTrueFalseTotal
read $fh, $buf, $size or die "TODO" 0 0 0
92 0 my $n = 0;
93 0 for my $byte ( unpack( 'c*', $buf ) ) {
94 0 $n <<= 8;
95 0 $n |= ( $byte & 255 );
96 }
97  
98 # negative?
99 0 ▶ return $val < -120 || ( $val >= -112 && $val <= 0 ) ? ~$n : $n;
Branch: 1 branch
BranchTrueFalseTotal
$val < -120 || $val >= -112 && $val <= 0 ? : 0 0 0
Condition0%0/6
$val < -120 or $val >= -112 and $val <= 0
l!l&&r!l&&!r
000
$val >= -112 and $val <= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$val < -120 or $val >= -112 and $val <= 0
$val < -120 $val >= -112 $val <= 0
Truth table0%0/4
A or B and C
A= $val < -120B= $val >= -112C= $val <= 0
ABCresult
1XX1
0111
00X0
0100
100 }
101 }
102  
103 0 ▶sub vlong {
Subroutine vlong: not called CC=5 SCAR=34.0
Pod documented
104 0 my ($long) = @_;
105 0 ▶ if ( $long >= -112 && $long <= 127 ) { return pack( 'c', $long ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($long >= -112 and $long <= 127) { } 0 0 0
Condition0%0/3
$long >= -112 and $long <= 127
!ll&&!rl&&r
000
MC/DC0%0/2
$long >= -112 and $long <= 127
$long >= -112 $long <= 127
Truth table0%0/3
A and B
A= $long >= -112B= $long <= 127
ABresult
0X0
100
111
106 else {
107 0 ▶ if ( $long < 0 ) { $long = ~$long }
Branch: 1 branch
BranchTrueFalseTotal
if ($long < 0) 0 0 0
108 0 my @bytes = unpack( 'C*', pack( 'q', $long ) );
109 0 ▶ pop @bytes while !$bytes[-1];
Branch: 1 branch
BranchTrueFalseTotal
$bytes[-1] or do { pop @bytes } 0 0 0
110 0 return pack( 'C*', @bytes );
111 }
112 }
113  
114 0 ▶sub _decode_size {
Subroutine _decode_size: not called CC=3 SCAR=24.8
115 0 my ($byte) = @_;
116 0 my $int = unpack( 'c', $byte );
117 0 ▶ return ( $int >= -112 )
Branch: 2 branches
BranchTrueFalseTotal
$int >= -112 ? : 0 0 0
$int < -120 ? : 0 0 0
118 ? 1
119 : ( ( $int < -120 ) ? ( -119 - $int ) : ( -111 - $int ) );
120 }
121  
122 1 1;
123  
124 __END__
↑ Summary IO/RCFile/Reader.pm »