BSON/Binary.pm

filter: Statementstmt 88.1% 37 / 42 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 6 totaltotal 79.4% 54 / 68 CC 4 SCAR 5.0
CC
4
Cov
88%
data
3.0
new
2.0
TO_JSON
2.0
CRAP 1.6
« BSON/Doc.pm ↑ Summary BSON/Bytes.pm »
1 71 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 71 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package BSON::Binary;
6 # ABSTRACT: Legacy BSON type wrapper for binary data (DEPRECATED)
7  
8 71 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 71 our $VERSION = 'v1.12.2';
10  
11 71 our $TYPE_SIMPLE = 0x00;
12 71 our $TYPE_BYTES = 0x02;
13 71 our $TYPE_UUID = 0x03;
14 71 our $TYPE_MD5 = 0x05;
15 71 our $TYPE_USER_DEFINED = 0x80;
16  
17 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
18 5 my ( $class, $data, $type ) = @_;
19 5 ▶ $type ||= $TYPE_SIMPLE;
Condition66%2/3
$type ||= $BSON::Binary::TYPE_SIMPLE
l!l&&r!l&&!r
203
MC/DC50%1/2
$type ||= $BSON::Binary::TYPE_SIMPLE
$type $BSON::Binary::TYPE_SIMPLE
Truth table66%2/3
A ||= B
A= $typeB= $BSON::Binary::TYPE_SIMPLE
ABresult
1X1
011
000
20 5 my $self = bless { type => $type }, $class;
21 5 $self->data($data);
22 5 return $self;
23 }
24  
25 15 ▶sub data {
Subroutine data: called CC=3 SCAR=11.0
Pod undocumented
26 15 my ( $self, $data ) = @_;
27 15 ▶ if ( defined $data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 5 10 15
28 5 ▶ $data = [ unpack( 'C*', $data ) ] unless ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "ARRAY" 3 2 5
29 5 $self->{data} = $data;
30 }
31 15 return $self->{data};
32 }
33  
34 6 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
35 6 return $_[0]->{type};
36 }
37  
38 # alias for compatibility with BSON::Bytes
39 4 ▶sub subtype {
Subroutine subtype: called CC=1 SCAR=0.0
Pod undocumented
40 4 return $_[0]->{type};
41 }
42  
43 2 ▶sub to_s {
Subroutine to_s: called CC=1 SCAR=0.0
Pod undocumented
44 2 my $self = shift;
45 2 my @data = @{ $self->data };
46 2 return pack( 'l<C*', scalar(@data), $self->type, @data );
47 }
48  
49 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my %data;
51 0 tie( %data, 'Tie::IxHash' );
52 0 $data{base64} = $_[0]->to_s;
53 0 $data{subType} = $_[0]->{type};
54 0 return { '$binary' => \%data };
55 }
56  
57 71 ▶use overload '""' => \&to_s;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 71 1;
60  
61 =pod
62  
63 =encoding UTF-8
64  
65 =head1 NAME
66  
67 BSON::Binary - Legacy BSON type wrapper for binary data (DEPRECATED)
68  
69 =head1 VERSION
70  
71 version v1.12.2
72  
73 =head1 DESCRIPTION
74  
75 This module has been deprecated as it was horribly inefficient (unpacking
76 binary data to individual single-byte elements of an array!) and had a
77 weird API that was not compatible with the existing MongoDB Binary wrapper
78 implementation on CPAN.
79  
80 You are strongly encouraged to use L<BSON::Bytes> instead.
81  
82 =for Pod::Coverage new data type subtype to_s TO_JSON
83  
84 =head1 AUTHORS
85  
86 =over 4
87  
88 =item *
89  
90 David Golden <david@mongodb.com>
91  
92 =item *
93  
94 Stefan G. <minimalist@lavabit.com>
95  
96 =back
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
101  
102 This is free software, licensed under:
103  
104 The Apache License, Version 2.0, January 2004
105  
106 =cut
107  
108 __END__
« BSON/Doc.pm ↑ Summary BSON/Bytes.pm »