line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MorboDB::OID; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: An object ID in MorboDB |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
23
|
use Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
27
|
|
6
|
4
|
|
|
4
|
|
1102
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4814
|
|
7
|
4
|
|
|
4
|
|
4490
|
use Data::UUID; |
|
4
|
|
|
|
|
3259
|
|
|
4
|
|
|
|
|
937
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "1.000000"; |
10
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
MorboDB::OID - An object ID in MorboDB |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
version 1.000000 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
When inserting documents into a collection, if you don't provide an '_id' |
23
|
|
|
|
|
|
|
attribute, this module will create one automatically. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $id = $collection->insert({ name => 'Alice', age => 20 }); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
C<$id> will be a C object that can be used to retreive or |
28
|
|
|
|
|
|
|
update the saved document: |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$collection->update({ _id => $id }, { age => { '$inc' => 1 } }); |
31
|
|
|
|
|
|
|
# now Alice is 21 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
To create a copy of an existing OID, you must set the value attribute in |
34
|
|
|
|
|
|
|
the constructor. For example: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $id1 = MongoDB::OID->new; |
37
|
|
|
|
|
|
|
my $id2 = MongoDB::OID->new(value => $id1->value); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Now C<$id1> and C<$id2> will have the same value. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
A MorboDB::OID object uniquely represents a document in a L. |
44
|
|
|
|
|
|
|
When you don't provide a documents with the '_id' attribute during insertion, |
45
|
|
|
|
|
|
|
this module will create an ID automatically. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
OIDs in MorboDB are created using L, so they are 36-characters |
48
|
|
|
|
|
|
|
long and do not resemble OIDs in MongoDB. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 value |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
A 36-characters long string representation of the OID in conventional UUID format. |
55
|
|
|
|
|
|
|
See L |
56
|
|
|
|
|
|
|
for more information on UUID format. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has 'value' => (is => 'ro', builder => '_build_value'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 to_string() |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This really just returns the 'value' attribute. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
1
|
0
|
sub to_string { shift->value } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 get_time() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Not implemented. Only returns C here. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
0
|
1
|
0
|
sub get_time { undef } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 TO_JSON() |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Meant to be called by the L family of modules to create a JSON |
83
|
|
|
|
|
|
|
representation of the OID. So, for example, "4162F712-1DD2-11B2-B17E-C09EFE1DC403" |
84
|
|
|
|
|
|
|
will be represented as C<{ "$oid" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403" }>. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $json = JSON->new->allow_blessed->convert_blessed; |
87
|
|
|
|
|
|
|
$json->encode(MorboDB::OID->new); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
1
|
0
|
sub TO_JSON { { '$oid' => shift->value } } |
92
|
|
|
|
|
|
|
|
93
|
9
|
|
|
9
|
|
5605
|
sub _build_value { Data::UUID->new->create_str } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This module does not throw any errors of its own. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
No bugs have been reported. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
104
|
|
|
|
|
|
|
C, or through the web interface at |
105
|
|
|
|
|
|
|
L. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L, L. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Ido Perlmuter |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright (c) 2011-2013, Ido Perlmuter C<< ido@ido50.net >>. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
120
|
|
|
|
|
|
|
modify it under the same terms as Perl itself, either version |
121
|
|
|
|
|
|
|
5.8.1 or any later version. See L |
122
|
|
|
|
|
|
|
and L. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The full text of the license can be found in the |
125
|
|
|
|
|
|
|
LICENSE file included with this module. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
130
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
131
|
|
|
|
|
|
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
132
|
|
|
|
|
|
|
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
133
|
|
|
|
|
|
|
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
134
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
135
|
|
|
|
|
|
|
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
136
|
|
|
|
|
|
|
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
137
|
|
|
|
|
|
|
NECESSARY SERVICING, REPAIR, OR CORRECTION. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
140
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
141
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
142
|
|
|
|
|
|
|
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
143
|
|
|
|
|
|
|
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
144
|
|
|
|
|
|
|
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
145
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
146
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
147
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
148
|
|
|
|
|
|
|
SUCH DAMAGES. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
153
|
|
|
|
|
|
|
__END__ |