-
-
14 Oct 2014 09:32:49 UTC
- Distribution: Nile
- Module version: 0.55
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (0)
- Testers (356 / 2 / 0)
- Kwalitee
Bus factor: 0- 18.75% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (203.22KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Archive::Zip
- Benchmark::Stopwatch
- CGI::Carp
- CGI::Simple
- CSS::Minifier
- Cache::Redis
- Capture::Tiny
- Crypt::RC4
- DBI
- DBI::Profile
- DBI::ProfileDumper
- Data::Dumper
- Data::Validate::URI
- DateTime
- Devel::StackTrace
- Devel::StackTrace::AsHTML
- Devel::StackTrace::WithLexicals
- Email::Address
- Email::Date::Format
- Email::Sender::Simple
- Email::Simple
- Email::Valid
- Encode
- File::Find::Rule
- File::Slurp
- HTML::Entities
- HTML::Packer
- HTTP::AcceptLanguage
- HTTP::Headers
- HTTP::Tiny
- Hash::AsObject
- IO::Compress::Gzip
- IO::Uncompress::Gunzip
- Import::Into
- JavaScript::Minifier
- Log::Tiny
- MIME::Base64
- MIME::Entity
- Memcached::Client
- Module::Load
- Module::Runtime
- MongoDB
- MongoDB::MongoClient
- MongoDB::OID
- Moose
- MooseX::Declare
- MooseX::MethodAttributes
- MooseX::NonMoose
- PadWalker
- Perl::Tidy
- Plack::Builder
- Plack::Middleware::Deflater
- Redis
- Scalar::Util
- Search::Elasticsearch
- Tie::IxHash
- Time::HiRes
- Time::Local
- URI
- URI::Escape
- XML::TreePP
- namespace::autoclean
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Nile::Plugin - Plugin base class for the Nile framework.
SYNOPSIS
DESCRIPTION
Nile::Plugin - Plugin base class for the Nile framework.
This module is the base class for plugins. You include it by using it which also makes itself as a parent class for the plugin and inherts the method setting which has the plugin setting loaded automatically from the config files.
Creating your first plugin
Hello
is simple like that, just create a module file calledHello.pm
in the folderNile/Plugin
and put the following code in it:package Nile::Plugin::Hello; our $VERSION = '0.55'; # this also extends Nile::Plugin, the plugin base class use Nile::Plugin; # optional our alternative for sub new {} called automaticall on object creation sub main { my ($self, $arg) = @_; # plugin settings from config files section my $setting = $self->setting(); #same as #my $setting = $self->setting("hello"); # get app context my $app = $self->app; # good to setup hooks here # run this hook after the "start" method $app->hook->after_start( sub { my ($me, @args) = @_; #... }); } sub welcome { my ($self) = @_; return "Hello world"; } 1;
Then inside other modules or plugins you can access this plugin as
# get the plugin object $hello = $app->plugin->hello; # or $hello = $app->plugin("Hello"); # if plugin name has sub modules my $redis = $app->plugin("Cache::Redis"); # call plugin method say $app->plugin->hello->welcome; # in general, you access plugins like this: $app->plugin->your_plugin_name->your_plugin_method([args]);
Plugins will be loaded automatically on the first time it is used and can be load on application startup in the
init
method:$app->init({ plugin => [ qw(hello) ], });
Plugins also can be loaded on application startup by setting the
autoload
variable in the plugin configuration in the config files.Example of plugin configuration to auto load on application startup:
<plugin> <hello> <autoload>1</autoload> </hello> </plugin>
At the plugin load, the plugin optional method
main
will be called automatically if it exists, this is an alternative for the methodnew
.Inside the plugin methods, you access the application context by the injected method
app
and you use it in this way:my $app = $self->app; $app->request->param("name"); ... $app->config->get("email");
Plugins that setup
hooks
must be set to autoload on startup for hooks to work as expected.setting()
# inside plugin classes, return current plugin class config settings my $setting = $self->setting(); my %setting = $self->setting(); # # inside plugin classes, return specific plugin class config settings my $setting = $self->setting("email"); my %setting = $self->setting("email");
Returns plugin class settings from configuration files loaded.
Helper plugin settings in config files must be in inside the plugin tag. The plugin class name can be lower case tag, so plugin
Email
can beemail
.Exampler settings for
email
andcache
plugins class below:<plugin> <email> <transport>Sendmail</transport> <sendmail>/usr/sbin/sendmail</sendmail> </email> <cache> <autoload>1</autoload> </cache> </plugin>
Bugs
This project is available on github at https://github.com/mewsoft/Nile.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Nile.
SOURCE
Source repository is at https://github.com/mewsoft/Nile.
SEE ALSO
See Nile for details about the complete framework.
AUTHOR
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
COPYRIGHT AND LICENSE
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm Nile
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.