line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MorboDB::Database; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A MorboDB database |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
27
|
use Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
25
|
|
6
|
4
|
|
|
4
|
|
1067
|
use Carp; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
215
|
|
7
|
4
|
|
|
4
|
|
2313
|
use MorboDB::Collection; |
|
4
|
|
|
|
|
105
|
|
|
4
|
|
|
|
|
1633
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "1.000000"; |
10
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
MorboDB::Database - A MorboDB database |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
version 1.000000 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use MorboDB; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $morbodb = MorboDB->new; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $db = $morbodb->get_database('my_database'); |
27
|
|
|
|
|
|
|
my $coll = $db->get_collection('articles'); |
28
|
|
|
|
|
|
|
# use $coll as described in MorboDB::Collection |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module is the API for handling databases in a L container. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 name |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The name of the database. String, required. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has 'name' => (is => 'ro', required => 1); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has '_top' => (is => 'ro', required => 1, weak_ref => 1); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has '_colls' => (is => 'ro', default => sub { {} }); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 collection_names() |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Returns a list with the names of all collections in the database. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
1
|
0
|
sub collection_names { sort keys %{$_[0]->_colls} } |
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 get_collection( $name ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a L object with the given name: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $db = $morbodb->get_database('users'); |
63
|
|
|
|
|
|
|
my $coll = $db->get_collection('users'); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Like MongoDB, you can create a child-collection (purely semantics really) |
66
|
|
|
|
|
|
|
by using dots, so 'users.admins' can be thought of as a child collection |
67
|
|
|
|
|
|
|
of users: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $admins = $db->get_collection('users.admins'); |
70
|
|
|
|
|
|
|
# or |
71
|
|
|
|
|
|
|
my $admins = $db->get_collection('users')->get_collection('admins'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_collection { |
76
|
5
|
|
|
5
|
1
|
985
|
my ($self, $name) = @_; |
77
|
|
|
|
|
|
|
|
78
|
5
|
50
|
|
|
|
27
|
confess "You must provide the name of the collection to get." |
79
|
|
|
|
|
|
|
unless $name; |
80
|
|
|
|
|
|
|
|
81
|
5
|
|
33
|
|
|
117
|
return $self->_colls->{$name} ||= MorboDB::Collection->new(name => $name, _database => $self); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 get_gridfs() |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Not implemented. Doesn't do anything here except returning false. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
|
sub get_gridfs { return } # not implemented |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 drop() |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Drops the database, removes any collections it had and data they had. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub drop { |
99
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
foreach (keys %{$self->_colls}) { |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$_->drop; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
delete $self->_top->_dbs->{$self->name}; |
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 last_error() |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Not implemented. Doesn't do anything here except returning false. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
0
|
1
|
|
sub last_error { return } # not implemented |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 run_command() |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Not implemented. Doesn't do anything here except returning false. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
1
|
|
sub run_command { return } # not implemented |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 eval() |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Not implemented. Doesn't do anything here except returning false. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
0
|
1
|
|
sub eval { return } # not implemented |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item C<< You must provide the name of the collection to get. >> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This error is returned by the C method when you do not |
140
|
|
|
|
|
|
|
provide it with the name of the database you want to get/create. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=back |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
No bugs have been reported. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
149
|
|
|
|
|
|
|
C, or through the web interface at |
150
|
|
|
|
|
|
|
L. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Ido Perlmuter |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright (c) 2011-2013, Ido Perlmuter C<< ido@ido50.net >>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
165
|
|
|
|
|
|
|
modify it under the same terms as Perl itself, either version |
166
|
|
|
|
|
|
|
5.8.1 or any later version. See L |
167
|
|
|
|
|
|
|
and L. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The full text of the license can be found in the |
170
|
|
|
|
|
|
|
LICENSE file included with this module. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
175
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
176
|
|
|
|
|
|
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
177
|
|
|
|
|
|
|
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
178
|
|
|
|
|
|
|
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
179
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
180
|
|
|
|
|
|
|
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
181
|
|
|
|
|
|
|
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
182
|
|
|
|
|
|
|
NECESSARY SERVICING, REPAIR, OR CORRECTION. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
185
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
186
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
187
|
|
|
|
|
|
|
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
188
|
|
|
|
|
|
|
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
189
|
|
|
|
|
|
|
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
190
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
191
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
192
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
193
|
|
|
|
|
|
|
SUCH DAMAGES. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
198
|
|
|
|
|
|
|
__END__ |