File Coverage

blib/lib/Dancer/Plugin/Mongo.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             # ABSTRACT: MongoDB plugin for the Dancer micro framework
2             package Dancer::Plugin::Mongo;
3              
4 1     1   25971 use strict;
  1         3  
  1         29  
5 1     1   5 use warnings;
  1         2  
  1         24  
6 1     1   761 use Dancer::Plugin;
  1         128318  
  1         99  
7 1     1   573 use MongoDB 0.38;
  0            
  0            
8              
9             our $VERSION = 0.03;
10              
11             my $settings = plugin_setting;
12             my $conn;
13              
14             ## return a connected MongoDB object
15             register mongo => sub {
16              
17             $conn ? $conn : $conn = MongoDB::Connection->new( _slurp_settings() ) ;
18              
19             return $conn;
20             };
21              
22             register_plugin;
23              
24             sub _slurp_settings {
25            
26             my $args = {};
27             for (qw/ host port username password w wtimeout auto_reconnect auto_connect
28             timeout db_name query_timeout find_master/) {
29             if (exists $settings->{$_}) {
30             $args->{$_} = $settings->{$_};
31             }
32             }
33              
34             return $args;
35             }
36              
37              
38             1;
39              
40             __END__
41             =pod
42              
43             =head1 NAME
44              
45             Dancer::Plugin::Mongo - MongoDB plugin for the Dancer micro framework
46              
47             =head1 VERSION
48              
49             version 0.03
50              
51             =head1 SYNOPSIS
52              
53             use Dancer;
54             use Dancer::Plugin::Mongo;
55              
56             get '/widget/view/:id' => sub {
57             my $widget = mongo->database->collection->find_one({ id => params->{id} });
58             }
59              
60             =head1 DESCRIPTION
61              
62             Dancer::Plugin::Mongo provides a wrapper around L<MongoDB>. Add the appropriate
63             configuraton options to your config.yml and then you can access a MongoDB database
64             using the 'mongo' keyword.
65              
66             To query the database, use the standard MongoDB syntax, described in
67             L<MongoDB::Collection>.
68              
69             =head1 CONFIGURATON
70              
71             Connection details will be taken from your Dancer application config file, and
72             should be specified as follows:
73              
74             plugins:
75             Mongo:
76             host:
77             port:
78             username:
79             password:
80             w:
81             wtimeout:
82             auto_reconnect:
83             auto_connect:
84             timeout:
85             db_name:
86             query_timeout:
87             find_master:
88              
89             All these configuration values are optional, full details are in the
90             L<MongoDB::Connection> documentation.
91              
92             =head1 AUTHOR
93              
94             Adam Taylor <ajct@cpan.org>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2010 by Adam Taylor.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut
104