Mango/BSON/Binary.pm

filter: Statementstmt 92.8% 13 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 90.4% 19 / 21 CC 1 SCAR 0.0
CC
1
Cov
93%
BEGIN
1.0
__ANON__
1.0
__ANON__
1.0
CRAP 1.0
« Mango/BSON/Time.pm ↑ Summary Mango/Auth.pm »
1 package Mango::BSON::Binary;
2 11 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use overload bool => sub {1}, '""' => sub { shift->data }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: not called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=1 SCAR=0.1
4  
5 11 ▶use Mojo::Util 'b64_encode';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 has [qw(data type)];
8  
9 1 ▶sub TO_JSON { b64_encode shift->data, '' }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
10  
11 11 1;
12  
13 =encoding utf8
14  
15 =head1 NAME
16  
17 Mango::BSON::Binary - Binary type
18  
19 =head1 SYNOPSIS
20  
21 use Mango::BSON::Binary;
22  
23 my $bin = Mango::BSON::Binary->new(data => $bytes, type => 'generic');
24 say $bin->data;
25  
26 =head1 DESCRIPTION
27  
28 L<Mango::BSON::Binary> is a container for the BSON binary type used by
29 L<Mango::BSON>. For C<JSON> implementations like L<Mojo::JSON>, that support
30 the C<TO_JSON> method, it will automatically C<Base64> encode the binary data.
31  
32 =head1 ATTRIBUTES
33  
34 L<Mango::BSON::Binary> implements the following attributes.
35  
36 =head2 data
37  
38 my $bytes = $bin->data;
39 $bin = $bin->data($bytes);
40  
41 Binary data.
42  
43 =head2 type
44  
45 my $type = $bin->type;
46 $bin = $bin->type('generic');
47  
48 Binary subtype.
49  
50 =head1 METHODS
51  
52 L<Mango::BSON::Binary> inherits all methods from L<Mojo::Base> and implements
53 the following new ones.
54  
55 =head2 TO_JSON
56  
57 my $b64 = $bin->TO_JSON;
58  
59 Base64 encode L</"data">.
60  
61 =head1 OPERATORS
62  
63 L<Mango::BSON::Binary> overloads the following operators.
64  
65 =head2 bool
66  
67 my $bool = !!$bin;
68  
69 Always true.
70  
71 =head2 stringify
72  
73 my $str = "$bin";
74  
75 Alias for L</data>.
76  
77 =head1 SEE ALSO
78  
79 L<Mango>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
80  
81 =cut
« Mango/BSON/Time.pm ↑ Summary Mango/Auth.pm »