The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CTK::App - Application interface

VERSION

Version 1.02

SYNOPSIS

use CTK::App;

my $ctk = CTK::App->new;
my $ctk = CTK::App->new(
    project => 'MyApp',
    ident => "myapp",
    root => ".",
    confopts    => {... Config::General options ...},
    configfile  => '/path/to/conf/file.conf',
    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',

See CTK::Configuration

ARGUMENTS

configfile

Path to the configuration file of the your project

Default: /etc/<PREFIX>/<PREFIX>.conf

See "configfile" in CTK

root
root => "/path/to/conf",

The main directory of project (confdir)

Default: /etc/<PREFIX>

See "root" in CTK

LOGGER

For logger enable 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"

See "level" in CTK::Log

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 = CTK::MyApp->new;
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

1.00 Mon 29 Apr 22:26:18 MSK 2019

Init version

See Changes file

TO DO

See TODO file

BUGS

* none noted

SEE ALSO

CTK, CTK::Helper

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2022 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/