line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Mongol; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5096
|
use Moose; |
|
2
|
|
|
|
|
569235
|
|
|
2
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Mojolicious::Plugin'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10363
|
use MongoDB; |
|
2
|
|
|
|
|
2356550
|
|
|
2
|
|
|
|
|
50
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
731
|
use Mongol; |
|
2
|
|
|
|
|
31904
|
|
|
2
|
|
|
|
|
336
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
14
|
0
|
|
|
0
|
1
|
|
my ( $self, $app, $config ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$app->attr( '_mongodb' => sub { |
17
|
0
|
|
0
|
0
|
|
|
return MongoDB->connect( $config->{host}, $config->{options} || {} ); |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
|
|
$app->helper( 'mongodb' => sub { shift()->app()->_mongodb() } ); |
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Here's where the magic happens ... |
24
|
0
|
|
|
|
|
|
Mongol->map_entities( $app->_mongodb(), %{ $config->{entities} } ); |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable( inline_constructor => 0 ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__END__ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=pod |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Mojolicious::Plugin::Mongol - Mongol plugin for Mojolicious |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub startup { |
42
|
|
|
|
|
|
|
my $self = shift(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->plugin( 'Mongol', |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
host => 'mongodb://localhost:27017', |
47
|
|
|
|
|
|
|
options => {}, |
48
|
|
|
|
|
|
|
entities => { |
49
|
|
|
|
|
|
|
'My::Models::Person' => 'db.people', |
50
|
|
|
|
|
|
|
'My::Models::Address' => 'db.addresses', |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L<Mongol> plugin for Mojolicious. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 HELPERS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 mongodb |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub action { |
66
|
|
|
|
|
|
|
my $self = shift(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $mongo = $self->mongodb(); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
... |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return $self->render( json => undef ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Just in case you need access to the MongoDB client instance you can use this helper to get it. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Tudor Marghidanu <tudor@marghidanu.com> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<Mongol> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |