| 1 | # Copyright Infomation | ||
| 2 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3 | # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. | ||
| 4 | # Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com | ||
| 5 | # Email : mewsoft@cpan.org, support@mewsoft.com | ||
| 6 | # Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved. | ||
| 7 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8 | package Nile::Plugin::MongoDB; | ||
| 9 | |||
| 10 | our $VERSION = '0.55'; | ||
| 11 | our $AUTHORITY = 'cpan:MEWSOFT'; | ||
| 12 | |||
| 13 | =pod | ||
| 14 | |||
| 15 | =encoding utf8 | ||
| 16 | |||
| 17 | =head1 NAME | ||
| 18 | |||
| 19 | Nile::Plugin::MongoDB - MongoDB plugin for the Nile framework. | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | # connect to MongoDB server | ||
| 24 | $client = $app->plugin->MongoDB; | ||
| 25 | |||
| 26 | # connect to database | ||
| 27 | my $db = $client->get_database("db_name"); | ||
| 28 | |||
| 29 | # connect to collection/table | ||
| 30 | my $table = $db->get_collection("users"); | ||
| 31 | |||
| 32 | my $id = $table->insert({ some => 'data' }); | ||
| 33 | my $data = $table->find_one({ _id => $id }); | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | Nile::Plugin::MongoDB - MongoDB plugin for the Nile framework. | ||
| 38 | |||
| 39 | # connect to MongoDB server | ||
| 40 | $client = $app->plugin->MongoDB; | ||
| 41 | |||
| 42 | Returns the L<MongoDB::MongoClient> object. All L<MongoDB::MongoClient> methods are supported. | ||
| 43 | |||
| 44 | Plugin settings in th config file under C<plugin> section. | ||
| 45 | |||
| 46 | <plugin> | ||
| 47 | |||
| 48 | <mongodb> | ||
| 49 | <server>localhost</server> | ||
| 50 | <port>27017</port> | ||
| 51 | <database></database> | ||
| 52 | <collection></collection> | ||
| 53 | </mongodb> | ||
| 54 | |||
| 55 | </plugin> | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | use Nile::Plugin; | ||
| 60 | use MongoDB; | ||
| 61 | use MongoDB::MongoClient; | ||
| 62 | use MongoDB::OID; | ||
| 63 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 64 | sub main { | ||
| 65 | my ($self, $arg) = @_; | ||
| 66 | my $app = $self->app; | ||
| 67 | my $setting = $self->setting(); | ||
| 68 | $setting->{host} ||= "localhost:27017"; | ||
| 69 | rebless => MongoDB::MongoClient->new(%{$setting}); | ||
| 70 | } | ||
| 71 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 72 | |||
| 73 | =pod | ||
| 74 | |||
| 75 | =head1 Bugs | ||
| 76 | |||
| 77 | This project is available on github at L<https://github.com/mewsoft/Nile>. | ||
| 78 | |||
| 79 | =head1 HOMEPAGE | ||
| 80 | |||
| 81 | Please visit the project's homepage at L<https://metacpan.org/release/Nile>. | ||
| 82 | |||
| 83 | =head1 SOURCE | ||
| 84 | |||
| 85 | Source repository is at L<https://github.com/mewsoft/Nile>. | ||
| 86 | |||
| 87 | =head1 SEE ALSO | ||
| 88 | |||
| 89 | See L<Nile> for details about the complete framework. | ||
| 90 | |||
| 91 | =head1 AUTHOR | ||
| 92 | |||
| 93 | Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> | ||
| 94 | Website: http://www.mewsoft.com | ||
| 95 | |||
| 96 | =head1 COPYRIGHT AND LICENSE | ||
| 97 | |||
| 98 | Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, | ||
| 99 | L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> | ||
| 100 | |||
| 101 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | 1; |