| Filename | /usr/local/lib/perl/5.10.1/MongoDB/Database.pm |
| Statements | Executed 23 statements in 1.03ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1000000 | 1 | 1 | 741ms | 741ms | MongoDB::Database::_connection (xsub) |
| 1 | 1 | 1 | 1.46ms | 160ms | MongoDB::Database::BEGIN@23 |
| 1 | 1 | 1 | 16µs | 417µs | MongoDB::Database::BEGIN@22 |
| 1 | 1 | 1 | 13µs | 127µs | MongoDB::Database::AUTOLOAD |
| 1 | 1 | 1 | 12µs | 154µs | MongoDB::Database::BEGIN@328 |
| 1 | 1 | 1 | 7µs | 110µs | MongoDB::Database::get_collection |
| 1 | 1 | 1 | 6µs | 4.07ms | MongoDB::Database::BUILD |
| 1 | 1 | 1 | 4µs | 4µs | MongoDB::Database::CORE:subst (opcode) |
| 1 | 1 | 1 | 800ns | 800ns | MongoDB::Database::name (xsub) |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::collection_names |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::drop |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::eval |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::get_gridfs |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::last_error |
| 0 | 0 | 0 | 0s | 0s | MongoDB::Database::run_command |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # | ||||
| 2 | # Copyright 2009 10gen, Inc. | ||||
| 3 | # | ||||
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| 5 | # you may not use this file except in compliance with the License. | ||||
| 6 | # You may obtain a copy of the License at | ||||
| 7 | # | ||||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||
| 9 | # | ||||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| 13 | # See the License for the specific language governing permissions and | ||||
| 14 | # limitations under the License. | ||||
| 15 | # | ||||
| 16 | |||||
| 17 | package MongoDB::Database; | ||||
| 18 | 1 | 900ns | our $VERSION = '0.42'; | ||
| 19 | |||||
| 20 | # ABSTRACT: A Mongo Database | ||||
| 21 | |||||
| 22 | 3 | 36µs | 2 | 818µs | # spent 417µs (16+401) within MongoDB::Database::BEGIN@22 which was called:
# once (16µs+401µs) by MongoDB::Connection::BEGIN@2 at line 22 # spent 417µs making 1 call to MongoDB::Database::BEGIN@22
# spent 401µs making 1 call to Any::Moose::import |
| 23 | 3 | 849µs | 1 | 160ms | # spent 160ms (1.46+159) within MongoDB::Database::BEGIN@23 which was called:
# once (1.46ms+159ms) by MongoDB::Connection::BEGIN@2 at line 23 # spent 160ms making 1 call to MongoDB::Database::BEGIN@23 |
| 24 | |||||
| 25 | 1 | 2µs | 1 | 214µs | has _connection => ( # spent 214µs making 1 call to Mouse::has |
| 26 | is => 'ro', | ||||
| 27 | isa => 'MongoDB::Connection', | ||||
| 28 | required => 1, | ||||
| 29 | ); | ||||
| 30 | |||||
| 31 | =head1 NAME | ||||
| 32 | |||||
| - - | |||||
| 57 | 1 | 2µs | 1 | 197µs | has name => ( # spent 197µs making 1 call to Mouse::has |
| 58 | is => 'ro', | ||||
| 59 | isa => 'Str', | ||||
| 60 | required => 1, | ||||
| 61 | ); | ||||
| 62 | |||||
| 63 | |||||
| 64 | # spent 127µs (13+114) within MongoDB::Database::AUTOLOAD which was called:
# once (13µs+114µs) by main::RUNTIME at line 16 of mongo_pain.pl | ||||
| 65 | 1 | 600ns | my $self = shift @_; | ||
| 66 | 1 | 200ns | our $AUTOLOAD; | ||
| 67 | |||||
| 68 | 1 | 400ns | my $coll = $AUTOLOAD; | ||
| 69 | 1 | 9µs | 1 | 4µs | $coll =~ s/.*:://; # spent 4µs making 1 call to MongoDB::Database::CORE:subst |
| 70 | |||||
| 71 | 1 | 6µs | 1 | 110µs | return $self->get_collection($coll); # spent 110µs making 1 call to MongoDB::Database::get_collection |
| 72 | } | ||||
| 73 | |||||
| 74 | # spent 4.07ms (6µs+4.06) within MongoDB::Database::BUILD which was called:
# once (6µs+4.06ms) by Mouse::Object::new at line 531 of MongoDB/Connection.pm | ||||
| 75 | 1 | 800ns | my ($self) = @_; | ||
| 76 | 1 | 4µs | 1 | 4.06ms | Any::Moose::load_class("MongoDB::Collection"); # spent 4.06ms making 1 call to Mouse::Util::load_class |
| 77 | } | ||||
| 78 | |||||
| 79 | =head1 METHODS | ||||
| 80 | |||||
| - - | |||||
| 89 | sub collection_names { | ||||
| 90 | my ($self) = @_; | ||||
| 91 | my $it = $self->get_collection('system.namespaces')->query({}); | ||||
| 92 | return map { | ||||
| 93 | substr($_, length($self->name) + 1) | ||||
| 94 | } map { $_->{name} } $it->all; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | =head2 get_collection ($name) | ||||
| 98 | |||||
| - - | |||||
| 106 | # spent 110µs (7+103) within MongoDB::Database::get_collection which was called:
# once (7µs+103µs) by MongoDB::Database::AUTOLOAD at line 71 | ||||
| 107 | 1 | 1µs | my ($self, $collection_name) = @_; | ||
| 108 | 1 | 59µs | 7 | 159µs | return MongoDB::Collection->new( # spent 103µs making 1 call to Mouse::Object::new
# spent 49µs making 1 call to Mouse::Meta::Class::_calculate_all_attributes
# spent 2µs making 1 call to Mouse::Meta::Class::strict_constructor
# spent 2µs making 2 calls to Mouse::Meta::TypeConstraint::_compiled_type_constraint, avg 1µs/call
# spent 1µs making 1 call to Mouse::Meta::Class::is_immutable
# spent 900ns making 1 call to Mouse::Meta::Class::is_anon_class |
| 109 | _database => $self, | ||||
| 110 | name => $collection_name, | ||||
| 111 | ); | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | =head2 get_gridfs ($prefix?) | ||||
| 115 | |||||
| - - | |||||
| 126 | sub get_gridfs { | ||||
| 127 | my ($self, $prefix) = @_; | ||||
| 128 | $prefix = "fs" unless $prefix; | ||||
| 129 | |||||
| 130 | return MongoDB::GridFS->new( | ||||
| 131 | _database => $self, | ||||
| 132 | prefix => $prefix | ||||
| 133 | ); | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | =head2 drop | ||||
| 137 | |||||
| - - | |||||
| 144 | sub drop { | ||||
| 145 | my ($self) = @_; | ||||
| 146 | return $self->run_command({ 'dropDatabase' => 1 }); | ||||
| 147 | } | ||||
| 148 | |||||
| 149 | |||||
| 150 | =head2 last_error($options?) | ||||
| 151 | |||||
| - - | |||||
| 256 | sub last_error { | ||||
| 257 | my ($self, $options) = @_; | ||||
| 258 | |||||
| 259 | my $cmd = Tie::IxHash->new("getlasterror" => 1); | ||||
| 260 | if ($options) { | ||||
| 261 | $cmd->Push("w", $options->{w}) if $options->{w}; | ||||
| 262 | $cmd->Push("wtimeout", $options->{wtimeout}) if $options->{wtimeout}; | ||||
| 263 | $cmd->Push("fsync", $options->{fsync}) if $options->{fsync}; | ||||
| 264 | } | ||||
| 265 | |||||
| 266 | return $self->run_command($cmd); | ||||
| 267 | } | ||||
| 268 | |||||
| 269 | |||||
| 270 | =head2 run_command ($command) | ||||
| 271 | |||||
| - - | |||||
| 288 | sub run_command { | ||||
| 289 | my ($self, $command) = @_; | ||||
| 290 | my $obj = $self->get_collection('$cmd')->find_one($command); | ||||
| 291 | return $obj if $obj->{ok}; | ||||
| 292 | $obj->{'errmsg'}; | ||||
| 293 | } | ||||
| 294 | |||||
| 295 | |||||
| 296 | =head2 eval ($code, $args?) | ||||
| 297 | |||||
| - - | |||||
| 312 | sub eval { | ||||
| 313 | my ($self, $code, $args) = @_; | ||||
| 314 | |||||
| 315 | my $cmd = tie(my %hash, 'Tie::IxHash'); | ||||
| 316 | %hash = ('$eval' => $code, | ||||
| 317 | 'args' => $args); | ||||
| 318 | |||||
| 319 | my $result = $self->run_command($cmd); | ||||
| 320 | if (ref $result eq 'HASH' && exists $result->{'retval'}) { | ||||
| 321 | return $result->{'retval'}; | ||||
| 322 | } | ||||
| 323 | else { | ||||
| 324 | return $result; | ||||
| 325 | } | ||||
| 326 | } | ||||
| 327 | |||||
| 328 | 3 | 43µs | 2 | 296µs | # spent 154µs (12+142) within MongoDB::Database::BEGIN@328 which was called:
# once (12µs+142µs) by MongoDB::Connection::BEGIN@2 at line 328 # spent 154µs making 1 call to MongoDB::Database::BEGIN@328
# spent 142µs making 1 call to Any::Moose::unimport |
| 329 | 1 | 7µs | 2 | 130µs | __PACKAGE__->meta->make_immutable; # spent 119µs making 1 call to Mouse::Meta::Class::make_immutable
# spent 11µs making 1 call to MongoDB::Database::meta |
| 330 | |||||
| 331 | 1 | 9µs | 1; | ||
| 332 | |||||
| 333 | =head1 AUTHOR | ||||
# spent 4µs within MongoDB::Database::CORE:subst which was called:
# once (4µs+0s) by MongoDB::Database::AUTOLOAD at line 69 | |||||
# spent 741ms within MongoDB::Database::_connection which was called 1000000 times, avg 741ns/call:
# 1000000 times (741ms+0s) by MongoDB::Collection::batch_insert at line 303 of MongoDB/Collection.pm, avg 741ns/call | |||||
# spent 800ns within MongoDB::Database::name which was called:
# once (800ns+0s) by MongoDB::Collection::_build_full_name at line 88 of MongoDB/Collection.pm |