Filename | /usr/local/lib/perl/5.14.2/MongoDB/DBRef.pm |
Statements | Executed 21 statements in 467µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 3.34ms | BEGIN@24 | MongoDB::DBRef::
1 | 1 | 1 | 8µs | 32µs | BEGIN@26 | MongoDB::DBRef::
1 | 1 | 1 | 8µs | 1.53ms | BEGIN@25 | MongoDB::DBRef::
1 | 1 | 1 | 5µs | 5µs | BEGIN@27 | MongoDB::DBRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:35] | MongoDB::DBRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:39] | MongoDB::DBRef::
0 | 0 | 0 | 0s | 0s | _ordered | MongoDB::DBRef::
0 | 0 | 0 | 0s | 0s | fetch | MongoDB::DBRef::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # | ||||
2 | # Copyright 2009-2013 MongoDB, 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::DBRef; | ||||
18 | { | ||||
19 | 2 | 1µs | $MongoDB::DBRef::VERSION = '0.702.2'; | ||
20 | } | ||||
21 | |||||
22 | # ABSTRACT: Native DBRef support | ||||
23 | |||||
24 | 2 | 34µs | 2 | 6.67ms | # spent 3.34ms (12µs+3.33) within MongoDB::DBRef::BEGIN@24 which was called:
# once (12µs+3.33ms) by MongoDB::BEGIN@32 at line 24 # spent 3.34ms making 1 call to MongoDB::DBRef::BEGIN@24
# spent 3.33ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:519] |
25 | 2 | 33µs | 2 | 3.05ms | # spent 1.53ms (8µs+1.52) within MongoDB::DBRef::BEGIN@25 which was called:
# once (8µs+1.52ms) by MongoDB::BEGIN@32 at line 25 # spent 1.53ms making 1 call to MongoDB::DBRef::BEGIN@25
# spent 1.52ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:519] |
26 | 2 | 24µs | 2 | 57µs | # spent 32µs (8+25) within MongoDB::DBRef::BEGIN@26 which was called:
# once (8µs+25µs) by MongoDB::BEGIN@32 at line 26 # spent 32µs making 1 call to MongoDB::DBRef::BEGIN@26
# spent 25µs making 1 call to Exporter::import |
27 | 2 | 334µs | 1 | 5µs | # spent 5µs within MongoDB::DBRef::BEGIN@27 which was called:
# once (5µs+0s) by MongoDB::BEGIN@32 at line 27 # spent 5µs making 1 call to MongoDB::DBRef::BEGIN@27 |
28 | |||||
29 | |||||
30 | 1 | 5µs | 2 | 509µs | subtype DBRefColl => as 'Str'; # spent 505µs making 1 call to Moose::Util::TypeConstraints::subtype
# spent 4µs making 1 call to Moose::Util::TypeConstraints::as |
31 | 1 | 3µs | 2 | 442µs | subtype DBRefDB => as 'Str'; # spent 440µs making 1 call to Moose::Util::TypeConstraints::subtype
# spent 2µs making 1 call to Moose::Util::TypeConstraints::as |
32 | |||||
33 | coerce 'DBRefColl' | ||||
34 | => from 'MongoDB::Collection' | ||||
35 | 1 | 6µs | 3 | 355µs | => via { $_->name }; # spent 351µs making 1 call to Moose::Util::TypeConstraints::coerce
# spent 2µs making 1 call to Moose::Util::TypeConstraints::from
# spent 2µs making 1 call to Moose::Util::TypeConstraints::via |
36 | |||||
37 | coerce 'DBRefDB' | ||||
38 | => from 'MongoDB::Database' | ||||
39 | 1 | 4µs | 3 | 236µs | => via { $_->name }; # spent 234µs making 1 call to Moose::Util::TypeConstraints::coerce
# spent 1µs making 1 call to Moose::Util::TypeConstraints::from
# spent 900ns making 1 call to Moose::Util::TypeConstraints::via |
40 | |||||
41 | |||||
42 | # no type constraint since an _id can be anything | ||||
43 | 1 | 2µs | 1 | 1.44ms | has id => ( # spent 1.44ms making 1 call to Moose::has |
44 | is => 'rw', | ||||
45 | required => 1 | ||||
46 | ); | ||||
47 | |||||
48 | 1 | 2µs | 1 | 2.12ms | has ref => ( # spent 2.12ms making 1 call to Moose::has |
49 | is => 'rw', | ||||
50 | isa => 'DBRefColl', | ||||
51 | required => 1, | ||||
52 | coerce => 1, | ||||
53 | ); | ||||
54 | |||||
55 | 1 | 1µs | 1 | 2.09ms | has db => ( # spent 2.09ms making 1 call to Moose::has |
56 | is => 'rw', | ||||
57 | isa => 'DBRefDB', | ||||
58 | required => 1, | ||||
59 | coerce => 1, | ||||
60 | ); | ||||
61 | |||||
62 | 1 | 1µs | 1 | 1.62ms | has client => ( # spent 1.62ms making 1 call to Moose::has |
63 | is => 'rw', | ||||
64 | isa => 'MongoDB::MongoClient', | ||||
65 | required => 0 | ||||
66 | ); | ||||
67 | |||||
68 | 1 | 1µs | 1 | 1.67ms | has verify_db => ( # spent 1.67ms making 1 call to Moose::has |
69 | is => 'rw', | ||||
70 | isa => 'Bool', | ||||
71 | required => 0, | ||||
72 | default => 1 | ||||
73 | ); | ||||
74 | |||||
75 | 1 | 1µs | 1 | 1.65ms | has verify_coll => ( # spent 1.65ms making 1 call to Moose::has |
76 | is => 'rw', | ||||
77 | isa => 'Bool', | ||||
78 | required => 0, | ||||
79 | default => 1 | ||||
80 | ); | ||||
81 | |||||
82 | |||||
83 | sub fetch { | ||||
84 | my $self = shift; | ||||
85 | |||||
86 | my $client = $self->client; | ||||
87 | |||||
88 | croak "Can't fetch DBRef without a MongoClient. Specify a 'client' attribute." | ||||
89 | unless $client; | ||||
90 | |||||
91 | my $db = $self->db; | ||||
92 | |||||
93 | if ( $self->verify_db ) { | ||||
94 | croak sprintf "No such database %s", $db | ||||
95 | unless grep { $_ eq $db } $client->database_names; | ||||
96 | } | ||||
97 | |||||
98 | my $ref = $self->ref; | ||||
99 | |||||
100 | if ( $self->verify_coll ) { | ||||
101 | croak sprintf "No such collection %s", $ref | ||||
102 | unless grep { $_ eq $ref } $client->get_database( $db )->collection_names; | ||||
103 | } | ||||
104 | |||||
105 | my $id = $self->id; | ||||
106 | |||||
107 | return $client->get_database( $db )->get_collection( $ref )->find_one( { _id => $id } ); | ||||
108 | } | ||||
109 | |||||
110 | sub _ordered { | ||||
111 | my $self = shift; | ||||
112 | |||||
113 | return Tie::IxHash->new( '$ref' => $self->ref, '$id' => $self->id, '$db' => $self->db ); | ||||
114 | } | ||||
115 | |||||
116 | 1 | 13µs | 1; | ||
117 | |||||
118 | __END__ |