File Coverage

blib/lib/BSON/ObjectId.pm
Criterion Covered Total %
statement 31 32 96.8
branch 8 8 100.0
condition 3 3 100.0
subroutine 9 10 90.0
pod 1 4 25.0
total 52 57 91.2


line stmt bran cond sub pod time code
1 71     71   24878 use 5.010001;
  71         215  
2 71     71   344 use strict;
  71         146  
  71         1419  
3 71     71   298 use warnings;
  71         120  
  71         2220  
4              
5             package BSON::ObjectId;
6             # ABSTRACT: Legacy BSON type wrapper for Object IDs (DEPRECATED)
7              
8 71     71   610 use version;
  71         131  
  71         286  
9             our $VERSION = 'v1.12.2';
10              
11 71     71   5127 use Carp;
  71         165  
  71         4032  
12              
13 71     71   398 use BSON::OID;
  71         152  
  71         20216  
14             our @ISA = qw/BSON::OID/;
15              
16             sub new {
17 9275     9275 1 183206 my ( $class, $value ) = @_;
18 9275         15219 my $self = bless {}, $class;
19 9275 100       16625 if ( $value ) {
20 7         18 $self->value( $value );
21             }
22             else {
23 9268         28563 $self->{oid} = BSON::OID::_packed_oid();
24             }
25 9273         26471 return $self;
26             }
27              
28             sub value {
29 9     9 0 20 my ( $self, $new_value ) = @_;
30 9 100       21 if ( defined $new_value ) {
31 7 100 100     27 if ( length($new_value) == 12 ) {
    100          
32 2         39 $self->{oid} = $new_value;
33             }
34             elsif ( length($new_value) == 24 && $self->is_legal($new_value) ) {
35 3         53 $self->{oid} = pack("H*", $new_value);
36             }
37             else {
38 2         278 croak("BSON::ObjectId must be a 12 byte or 24 char hex value");
39             }
40             }
41 7         20 return $self->{oid};
42             }
43              
44             sub is_legal {
45 5     5 0 31 $_[1] =~ /^[0-9a-f]{24}$/i;
46             }
47              
48 0     0 0   sub to_s { $_[0]->to_string }
49              
50             1;
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             BSON::ObjectId - Legacy BSON type wrapper for Object IDs (DEPRECATED)
59              
60             =head1 VERSION
61              
62             version v1.12.2
63              
64             =head1 DESCRIPTION
65              
66             This module has been deprecated as it was not compatible with
67             the official MongoDB BSON implementation on CPAN.
68              
69             You are strongly encouraged to use L instead.
70              
71             =for Pod::Coverage to_s is_legal new value
72              
73             =head1 AUTHORS
74              
75             =over 4
76              
77             =item *
78              
79             David Golden
80              
81             =item *
82              
83             Stefan G.
84              
85             =back
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
90              
91             This is free software, licensed under:
92              
93             The Apache License, Version 2.0, January 2004
94              
95             =cut
96              
97             __END__