NAME
CTK::App - Application interface
VERSION
Version 1.01
SYNOPSIS
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',
);
DESCRIPTION
The module provides application functionality
Features:
Configuration supported as CTK plugin
Logging supported as CTK plugin
CONFIGURATION
For enabling configuration specify the follow arguments in constructor:
root => "/path/to/conf",
configfile => '/path/to/conf/file.conf',
ARGUMENTS
- configfile
-
Path to the configuration file of the your project
Default: /etc/<PREFIX>/<PREFIX>.conf
- root
-
root => "/path/to/conf",
The main directory of project (confdir)
Default: /etc/<PREFIX>
See "root" in CTK
LOGGER
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,
ARGUMENTS
- ident
-
ident => "foo"
Ident string for logs and debugging
Default: <PROJECT>
See "ident" in CTK
- logfacility
-
logfacility => Sys::Syslog::LOG_USER
Sets facility. See "facility" in CTK::Log and Sys::Syslog
- logfile
-
logfile => '/var/log/myapp/myapp.log'
Full path to the log file
Default: syslog
See "logfile" in CTK
- no_logger_init
-
Set to 1 for forcing disabling automatic logger initialization on start the your application
Default: 0 (logger is enabled)
- loglevel
-
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"
- logopts
-
logopts => { utf8 => undef, # Default: 1 syslogopts => undef, # Defaukt: "ndelay,pid" socketopts => undef, # Default: undef pure => undef, # Default: 0 separator => undef, # Default: " " }
Default: undef
Logger options. See See "new" in CTK::Log
METHODS
List of application methods
again
This method is called immediately after creating the CTK object.
Internal use only!
handle
$ctk->handle($handler, @params) or die $ctk->error;
Runs handler with parameters
Internal use only!
list_handlers
my @handlers = $ctk->list_handlers
Returns list of registered handlers
lookup_handler
my $handler = $ctk->lookup_handler($name) or die "Handler lookup failed";
Lookup handler by name. Returns handler or undef while error
register_handler
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
run, run_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
],
};
HISTORY
See Changes
file
TO DO
See TODO
file
BUGS
* none noted
SEE ALSO
AUTHOR
Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>
COPYRIGHT
Copyright (C) 1998-2020 D&D Corporation. All Rights Reserved
LICENSE
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/