| 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::Int32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: BSON type wrapper for Int32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 71 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 71 | our $VERSION = 'v1.12.1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 71 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 71 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | #pod =attr value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | #pod A numeric scalar. It will be coerced to an integer. The default is 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 71 | has 'value' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'ro' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 71 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 71 | my $max_int32 = 2147483647; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 71 | my $min_int32 = -2147483648; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 91 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # coerce to IV internally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 91 | ▶ | $self->{value} = defined( $self->{value} ) ? int( $self->{value} ) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 91 | ▶ | if ( $self->{value} > $max_int32 || $self->{value} < $min_int32 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"value"} > $max_int32 or $self->{"value"} < $min_int32
MC/DC100%2/2
$self->{"value"} > $max_int32 or $self->{"value"} < $min_int32
$self->{"value"} > $max_int32
$self->{"value"} < $min_int32
Truth table100%3/3
A or B
A= $self->{"value"} > $max_int32B= $self->{"value"} < $min_int32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | croak("The value '$self->{value}' can't fit in a signed Int32"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #pod =method TO_JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #pod Returns the value as an integer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod If the C<BSON_EXTJSON> environment variable is true and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod C<BSON_EXTJSON_RELAXED> environment variable is false, returns a hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #pod compatible with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | #pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | #pod format, which represents it as a document as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | #pod {"$numberInt" : "42"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub TO_JSON { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 40 | ▶ | return int($_[0]->{value}) if ! $ENV{BSON_EXTJSON} || $ENV{BSON_EXTJSON_RELAXED}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
not $ENV{"BSON_EXTJSON"} or $ENV{"BSON_EXTJSON_RELAXED"}
MC/DC100%2/2
not $ENV{"BSON_EXTJSON"} or $ENV{"BSON_EXTJSON_RELAXED"}
not $ENV{"BSON_EXTJSON"}
$ENV{"BSON_EXTJSON_RELAXED"}
Truth table100%3/3
not(A) or B
A= not $ENV{"BSON_EXTJSON"}B= $ENV{"BSON_EXTJSON_RELAXED"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 33 | return { '$numberInt' => "$_[0]->{value}" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Unary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | q{""} => sub { "$_[0]->{value}" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | q{0+} => sub { $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | q{~} => sub { ~( $_[0]->{value} ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Binary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 142 | ▶ | ( map { $_ => eval "sub { return \$_[0]->{value} $_ \$_[1] }" } qw( + * ) ), ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 852 | ▶ | $_ => eval ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | "sub { return \$_[2] ? \$_[1] $_ \$_[0]->{value} : \$_[0]->{value} $_ \$_[1] }" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } qw( - / % ** << >> x <=> cmp & | ^ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 426 | ▶ | map { $_ => eval "sub { return $_(\$_[0]->{value}) }" } ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | qw( cos sin exp log sqrt int ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | q{atan2} => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return $_[2] ? atan2( $_[1], $_[0]->{value} ) : atan2( $_[0]->{value}, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Special | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 71 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 71 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 71 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | BSON::Int32 - BSON type wrapper for Int32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | version v1.12.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | use BSON::Types ':all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | bson_int32( $number ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | This module provides a BSON type wrapper for a numeric value that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | would be represented in BSON as a 32-bit integer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | If the value won't fit in a 32-bit integer, an error will be thrown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head2 value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | A numeric scalar. It will be coerced to an integer. The default is 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =head2 TO_JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Returns the value as an integer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | If the C<BSON_EXTJSON> environment variable is true and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | C<BSON_EXTJSON_RELAXED> environment variable is false, returns a hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | compatible with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | format, which represents it as a document as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | {"$numberInt" : "42"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =for Pod::Coverage BUILD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 OVERLOADING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | The numification operator, C<0+> is overloaded to return the C<value>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | the full "minimal set" of overloaded operations is provided (per L<overload> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | documentation) and fallback overloading is enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | David Golden <david@mongodb.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | Stefan G. <minimalist@lavabit.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | This software is Copyright (c) 2019 by Stefan G. and MongoDB, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||