| 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::String; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: BSON type wrapper for strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 71 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 71 | our $VERSION = 'v1.12.2'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 71 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #pod =attr value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #pod A scalar value, which will be stringified during construction. The default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | #pod is the empty string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 27007 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 27007 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 27007 | my $n = scalar(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 27007 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 27007 | ▶ | if ( $n == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $args{value} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | elsif ( $n == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 26983 | $args{value} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | elsif ( $n % 2 == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 23 | %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 23 | ▶ | $args{value} = '' unless defined $args{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | croak("Invalid number of arguments ($n) to BSON::String::new"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # normalize all to internal PV type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 27007 | $args{value} = "$args{value}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 27007 | return \%args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | #pod =method TO_JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #pod Returns value as a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | sub TO_JSON { return "$_[0]->{value}" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 71 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Unary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | q{bool} => sub { !! $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 44171 | ▶ | q{""} => sub { $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | q{0+} => sub { 0+ $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | q{~} => sub { ~( $_[0]->{value} ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Binary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | ( map { $_ => eval "sub { return \$_[0]->{value} $_ \$_[1] }" } qw( + * ) ), ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $_ => eval ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Subroutine
__ANON__: not called CC=2 SCAR=16.3
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | "sub { return \$_[2] ? \$_[1] $_ \$_[0]->{value} : \$_[0]->{value} $_ \$_[1] }" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } qw( - / % ** << >> x <=> cmp & | ^ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | map { $_ => eval "sub { return $_(\$_[0]->{value}) }" } ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | qw( cos sin exp log sqrt int ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | q{atan2} => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $_[2] ? atan2( $_[1], $_[0]->{value} ) : atan2( $_[0]->{value}, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Special | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 71 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 71 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 71 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | BSON::String - BSON type wrapper for strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | version v1.12.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | use BSON::Types ':all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | bson_string( $string ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | This module provides a BSON type wrapper for a string value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | Since Perl does not distinguish between numbers and strings, this module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | provides an explicit string type for a scalar value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | A scalar value, which will be stringified during construction. The default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | is the empty string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | =head2 TO_JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | Returns value as a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =for Pod::Coverage BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 OVERLOADING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | The stringification operator (C<"">) is overloaded to return the C<value>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | the full "minimal set" of overloaded operations is provided (per L<overload> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | documentation) and fallback overloading is enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | David Golden <david@mongodb.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | Stefan G. <minimalist@lavabit.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||