| 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::Memcached; | ||
| 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::Memcached - Memcached client plugin for the Nile framework. | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | # connect to Memcached servers | ||
| 24 | my $client = $app->plugin->memcached; | ||
| 25 | |||
| 26 | # store some data | ||
| 27 | $client->set("Name"=>"Ahmed Amin Elsheshtawy Gouda"); | ||
| 28 | |||
| 29 | # get some data | ||
| 30 | my $name = $client->get("Name"); | ||
| 31 | |||
| 32 | # delete some data | ||
| 33 | $client->delete("Name"); | ||
| 34 | |||
| 35 | # get the Memcached::Client object used | ||
| 36 | $object = $client->client; | ||
| 37 | |||
| 38 | =head1 DESCRIPTION | ||
| 39 | |||
| 40 | Nile::Plugin::Memcached - Memcached client plugin for the Nile framework. | ||
| 41 | |||
| 42 | Returns L<Memcached::Client> object. All methods of L<Memcached::Client> are supported. | ||
| 43 | |||
| 44 | Plugin settings in th config file under C<plugin> section. | ||
| 45 | |||
| 46 | <plugin> | ||
| 47 | |||
| 48 | <memcached> | ||
| 49 | <servers>localhost:11211</servers> | ||
| 50 | <namespace></namespace> | ||
| 51 | </memcached> | ||
| 52 | |||
| 53 | </plugin> | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | use Nile::Plugin; | ||
| 58 | use Memcached::Client; | ||
| 59 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 60 | sub main { | ||
| 61 | my ($self, $arg) = @_; | ||
| 62 | my $app = $self->app; | ||
| 63 | my $setting = $self->setting(); | ||
| 64 | if (defined($setting->{servers}) && (ref($setting->{servers}) ne "ARRAY")) { | ||
| 65 | $setting->{servers} = [$setting->{servers}]; | ||
| 66 | } | ||
| 67 | rebless => Memcached::Client->new($setting); | ||
| 68 | } | ||
| 69 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 70 | |||
| 71 | =pod | ||
| 72 | |||
| 73 | =head1 Bugs | ||
| 74 | |||
| 75 | This project is available on github at L<https://github.com/mewsoft/Nile>. | ||
| 76 | |||
| 77 | =head1 HOMEPAGE | ||
| 78 | |||
| 79 | Please visit the project's homepage at L<https://metacpan.org/release/Nile>. | ||
| 80 | |||
| 81 | =head1 SOURCE | ||
| 82 | |||
| 83 | Source repository is at L<https://github.com/mewsoft/Nile>. | ||
| 84 | |||
| 85 | =head1 SEE ALSO | ||
| 86 | |||
| 87 | See L<Nile> for details about the complete framework. | ||
| 88 | |||
| 89 | =head1 AUTHOR | ||
| 90 | |||
| 91 | Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> | ||
| 92 | Website: http://www.mewsoft.com | ||
| 93 | |||
| 94 | =head1 COPYRIGHT AND LICENSE | ||
| 95 | |||
| 96 | Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, | ||
| 97 | L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> | ||
| 98 | |||
| 99 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 100 | |||
| 101 | =cut | ||
| 102 | |||
| 103 | 1; |