File Coverage

blib/lib/BSON/Doc.pm
Criterion Covered Total %
statement 32 35 91.4
branch 6 6 100.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 47 52 90.3


line stmt bran cond sub pod time code
1 71     71   32396 use 5.010001;
  71         243  
2 71     71   362 use strict;
  71         140  
  71         1349  
3 71     71   314 use warnings;
  71         117  
  71         2102  
4              
5             package BSON::Doc;
6             # ABSTRACT: BSON type wrapper for ordered documents
7              
8 71     71   332 use version;
  71         123  
  71         377  
9             our $VERSION = 'v1.12.2';
10              
11 71     71   17532 use Carp qw/croak/;
  71         150  
  71         4995  
12 71     71   443 use Tie::IxHash;
  71         141  
  71         16092  
13              
14             sub new {
15 61     61 0 189 my ( $class, @args ) = @_;
16              
17 61 100       3844 croak "BSON::Doc::new requires key/value pairs"
18             if @args % 2 != 0;
19              
20 20         27 my $key_count =()= keys %{{@args}};
  20         76  
21 20 100       254 croak "Duplicate keys not allowed in BSON::Doc"
22             if $key_count * 2 != @args;
23              
24 19         94 return bless \@args, $class;
25             }
26              
27             sub _as_tied_hash {
28 0     0   0 my $self = shift;
29 0         0 tie my %h, 'Tie::IxHash', @$self;
30 0         0 return \%h;
31             }
32              
33             sub _iterator {
34 17     17   25 my $self = shift;
35 17         26 my $index = 0;
36             return sub {
37 40 100   40   51 return if $index > $#{$self};
  40         120  
38 23         40 my ($k,$v) = @{$self}[$index, $index+1];
  23         48  
39 23         30 $index += 2;
40 23         75 return ($k,$v);
41             }
42 17         78 }
43              
44             1;
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             BSON::Doc - BSON type wrapper for ordered documents
53              
54             =head1 VERSION
55              
56             version v1.12.2
57              
58             =head1 SYNOPSIS
59              
60             use BSON::Types ':all';
61              
62             my $ordered = bson_doc( first => 1, second => 2 );
63              
64             =head1 DESCRIPTION
65              
66             This module provides a BSON type wrapper representing a document preserves
67             key-value order. It is currently read-only.
68              
69             =for Pod::Coverage new
70              
71             =head1 AUTHORS
72              
73             =over 4
74              
75             =item *
76              
77             David Golden
78              
79             =item *
80              
81             Stefan G.
82              
83             =back
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
88              
89             This is free software, licensed under:
90              
91             The Apache License, Version 2.0, January 2004
92              
93             =cut
94              
95             __END__