line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mongol; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1169605
|
use Moose; |
|
2
|
|
|
|
|
662954
|
|
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
9110
|
use Moose::Util qw( does_role ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
274
|
use Class::Load qw( load_class ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
332
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.2'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub map_entities { |
11
|
0
|
|
|
0
|
1
|
|
my ( $class, $connection, %entities ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
while( my ( $name, $namespace ) = each( %entities ) ) { |
14
|
0
|
|
|
|
|
|
my $package = load_class( $name ); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if( does_role( $package, 'Mongol::Roles::Core' ) ) { |
17
|
0
|
|
|
|
|
|
$package->collection( $connection->get_namespace( $namespace ) ); |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
$package->setup() |
20
|
|
|
|
|
|
|
if( $package->can( 'setup' ) ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__END__ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=pod |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Mongol - MongoDB ODM for Moose objects |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package Models::Person { |
40
|
|
|
|
|
|
|
use Moose; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
extends 'Mongol::Model'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
with 'Mongol::Roles::Core'; |
45
|
|
|
|
|
|
|
with 'Mongol::Roles::Pagination'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'first_name' => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
isa => 'Str', |
50
|
|
|
|
|
|
|
required => 1, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'last_name' => ( |
54
|
|
|
|
|
|
|
is => 'ro', |
55
|
|
|
|
|
|
|
isa => 'Str', |
56
|
|
|
|
|
|
|
required => 1, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package main { |
63
|
|
|
|
|
|
|
... |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use MongoDB; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Mongol; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $mongo = MongoDB->connect(...); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Mongol->map_entities( $mongo, |
72
|
|
|
|
|
|
|
'Models::Person' => 'test.people', |
73
|
|
|
|
|
|
|
... |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
... |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 map_entities |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Mongol->map_entities( $mongo_connection, |
86
|
|
|
|
|
|
|
'My::Model::Class' => 'db.collection', |
87
|
|
|
|
|
|
|
'My::Model::Other' => 'db.other_collection', |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Using a given MongoDB connection will automatically map a model class to a collection. |
91
|
|
|
|
|
|
|
After each initialization if exists the B<setup> method on the model will be called. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Tudor Marghidanu <tudor@marghidanu.com> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<Moose> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L<MongoDB> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |