| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Mango; |
|
2
|
2
|
|
|
2
|
|
2119
|
use Modern::Perl; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
17
|
|
|
3
|
2
|
|
|
2
|
|
1059
|
use Mango; |
|
|
2
|
|
|
|
|
278966
|
|
|
|
2
|
|
|
|
|
27
|
|
|
4
|
2
|
|
|
2
|
|
91
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
11
|
|
|
5
|
2
|
|
|
2
|
|
2647
|
use namespace::clean; |
|
|
2
|
|
|
|
|
30313
|
|
|
|
2
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; # VERSION |
|
8
|
|
|
|
|
|
|
# ABSTRACT: provide mango helpers to Mojolicious |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
|
11
|
1
|
|
|
1
|
1
|
50
|
my $self = shift; |
|
12
|
1
|
|
|
|
|
1
|
my $app = shift; |
|
13
|
1
|
|
50
|
|
|
4
|
my $conf = shift || {}; |
|
14
|
1
|
|
50
|
|
|
7
|
$conf->{helper} ||= 'db'; |
|
15
|
1
|
|
50
|
|
|
7
|
$conf->{default_db} ||= 'test'; |
|
16
|
|
|
|
|
|
|
$app->attr('_mango' => sub { |
|
17
|
1
|
|
|
1
|
|
15010
|
my $m = Mango->new($conf->{mango}); |
|
18
|
1
|
|
|
|
|
34
|
$m->default_db($conf->{default_db}); |
|
19
|
1
|
50
|
|
|
|
8
|
$m->hosts($conf->{hosts}) if $conf->{hosts}; |
|
20
|
1
|
|
|
|
|
7
|
$m; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
1
|
|
|
|
|
10
|
); |
|
23
|
1
|
|
|
1
|
|
159
|
$app->helper('mango' => sub { shift; Mango->new(@_) }); |
|
|
1
|
|
|
|
|
38876
|
|
|
|
1
|
|
|
|
|
10
|
|
|
24
|
|
|
|
|
|
|
$app->helper($conf->{helper} => sub { |
|
25
|
3
|
|
|
3
|
|
41870
|
my $self = shift; |
|
26
|
3
|
|
|
|
|
80
|
return $self->app->_mango->db(@_); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
1
|
|
|
|
|
115
|
); |
|
29
|
|
|
|
|
|
|
$app->helper('hosts' => sub { |
|
30
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
31
|
0
|
|
|
|
|
0
|
return $self->app->_mango->hosts(@_); |
|
32
|
1
|
|
|
|
|
63
|
}); |
|
33
|
|
|
|
|
|
|
$app->helper('default_db' => sub { |
|
34
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
35
|
0
|
|
|
|
|
0
|
return $self->app->_mango->default_db(@_); |
|
36
|
1
|
|
|
|
|
57
|
}); |
|
37
|
|
|
|
|
|
|
$app->helper('coll' => sub { |
|
38
|
1
|
|
|
1
|
|
14637
|
my $self = shift; |
|
39
|
1
|
|
|
|
|
18
|
return $self->app->_mango->db->collection(@_); |
|
40
|
1
|
|
|
|
|
58
|
}); |
|
41
|
1
|
|
|
|
|
54
|
for my $helper (qw/get_more kill_cursors query/) { |
|
42
|
3
|
50
|
|
|
|
117
|
next if (defined ($conf->{"no_$helper"})); |
|
43
|
|
|
|
|
|
|
$app->helper($helper => sub { |
|
44
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
45
|
0
|
|
|
|
|
0
|
$self->app->_mango->$helper(@_); |
|
46
|
|
|
|
|
|
|
}) |
|
47
|
3
|
|
|
|
|
12
|
} |
|
48
|
1
|
|
|
|
|
58
|
for my $helper (qw/collection collection_names command dereference gridfs stats/) { |
|
49
|
6
|
50
|
|
|
|
285
|
next if (defined ($conf->{"no_$helper"})); |
|
50
|
|
|
|
|
|
|
$app->helper($helper => sub { |
|
51
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
|
$self->app->_mango->db->$helper(@_); |
|
53
|
|
|
|
|
|
|
}) |
|
54
|
6
|
|
|
|
|
21
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |