CTK::App - Application interface
Version 1.00
use CTK::App; my $ctk = new CTK::App; my $ctk = new CTK::App ( project => 'MyApp', ident => "myapp", root => ".", confopts => {... Config::General options ...}, configfile => '/path/to/conf/file.conf', log => 1, logfile => '/path/to/log/file.log', );
The module provides application functionality
Features:
Configuration supported as CTK plugin
Logging supported as CTK plugin
For enabling configuration specify the follow arguments in constructor:
root => "/path/to/conf", configfile => '/path/to/conf/file.conf',
See CTK::Configuration
Path to the configuration file of the your project
Default: /etc/<PREFIX>/<PREFIX>.conf
See "configfile" in CTK
root => "/path/to/conf",
The main directory of project (confdir)
Default: /etc/<PREFIX>
See "root" in CTK
For enabling logger specify the follow arguments in constructor:
log => 1,
And include follow config-section:
# # Logging # # Activate or deactivate the logging: on/off (yes/no). Default: off # LogEnable on # # Loglevel: debug, info, notice, warning, error, # crit, alert, emerg, fatal, except # Default: debug # LogLevel debug # # LogIdent string. Default: none # #LogIdent "foo" # # LogFile: path to log file # # Default: using syslog # #LogFile /var/log/foo.log
For forcing disable this logger specify the follow arguments in constructor:
no_logger_init => 1,
ident => "foo"
Ident string for logs and debugging
Default: <PROJECT>
See "ident" in CTK
logfacility => Sys::Syslog::LOG_USER
Sets facility. See "facility" in CTK::Log and Sys::Syslog
logfile => '/var/log/myapp/myapp.log'
Full path to the log file
Default: syslog
See "logfile" in CTK
Set to 1 for forcing disabling automatic logger initialization on start the your application
Default: 0 (logger is enabled)
loglevel => "info"
This directive specifies the minimum possible priority level. You can use:
'debug' 'info' 'notice' or 'note' 'warning' or 'warn' 'error' or 'err' 'crit' 'alert' 'emerg' or 'emergency' 'fatal' 'except' or 'exception'
Default: "debug"
See "level" in CTK::Log
logopts => { utf8 => undef, # Default: 1 syslogopts => undef, # Defaukt: "ndelay,pid" socketopts => undef, # Default: "unix" pure => undef, # Default: 0 separator => undef, # Default: " " }
Default: undef
Logger options. See See "new" in CTK::Log
List of application methods
This method is called immediately after creating the CTK object.
Internal use only!
$ctk->handle($handler, @params) or die $ctk->error;
Runs handler with parameters
my @handlers = $ctk->list_handlers
Returns list of registered handlers
my $handler = $ctk->lookup_handler($name) or die "Handler lookup failed";
Lookup handler by name. Returns handler or undef while error
use base qw/ CTK::App /; __PACKAGE__->register_handler( handler => "foo", description => "Foo CLI handler", parameters => { param1 => "foo", param2 => "bar", param3 => 123, }, code => sub { ### CODE: my $self = shift; my $meta = shift; my @params = @_; $self->debug(Dumper({ meta => $meta, params => [@params], })); return 1; });
Method for register new cli handler
my $app = new CTK::MyApp; my $result = $app->run("foo", foo => "one", bar => 1 ) or die $app->error;
Run handler by name
Example of result:
{ 'meta' => { 'params' => { 'param3' => 123, 'param1' => 'foo', 'param2' => 'bar' }, 'name' => 'foo', 'description' => 'Foo CLI handler' }, 'params' => [ 'foo', 'one', 'bar', 1 ], };
Init version
See Changes file
Changes
See TODO file
TODO
* none noted
CTK, CTK::Helper
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE file and https://dev.perl.org/licenses/
LICENSE
To install CTK, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CTK
CPAN shell
perl -MCPAN -e shell install CTK
For more information on module installation, please visit the detailed CPAN module installation guide.