CTK - CTK ToolKit library (CTKlib)
Version 2.09
The 2.00+ versions of this library is not compatible with earlier versions
use CTK; my $ctk = CTK->new; my $ctk = CTK->new ( project => 'MyApp', configfile => '/path/to/conf/file.conf', logfile => '/path/to/log/file.log', );
CTKlib - is library that provides "extended-features" (utilities) for your robots written on Perl. Most of the functions and methods this module written very simple language and easy to understand. To work with CTKlib, you just need to start using it!
my $ctk = CTK->new; my $ctk = CTK->new ( project => 'MyApp', configfile => '/path/to/conf/file.conf', logfile => '/path/to/log/file.log', );
Main constructor. All the params are optional
configfile => '/etc/myapp/myapp.conf'
Path to the configuration file of the your project
Default: /etc/<PREFIX>/<PREFIX>.conf
datadir => '/path/to/your/data/dir'
Directory for application data storing
Default: <getcwd()> (current directory)
debug => 1 debug => 'on' debug => 'yes'
Debug mode
Default: 0
ident => "test"
Ident string for logs and debugging
Default: ""
log => 1 log => 'on' log => 'yes'
Log mode. For debug and error methods only!!
logdir => '/var/log/myapp'
Log directory of project
Default: /var/log/<PREFIX>
logfile => '/var/log/myapp/myapp.log'
Full path to the log file
Default: /var/log/<PREFIX>/<PREFIX>.log
options => {foo => 'bar'}
Command-line options, hash-ref structure. See Getopt::Long
Default: {}
plugins => [qw/ test /] plugins => "test"
Array ref of plugin list or plugin name as scalar:
Default: []
prefix => "myapp"
Prefix of the Your project
Default: lc(<PROJECT>)
project => "MyApp" name => "MyApp"
Project name
Default: $FindBin::Script without file extension
root => "/etc/myapp"
Root dir of project
Default: /etc/<PREFIX>
suffix => "devel" suffix => "alpha" suffix => "beta" suffix => ".dev"
Suffix of the your project. Can use in plugins
tempdir => "/tmp/myapp"
Temp directory of project
Default: /tmp/<PREFIX>
tempfile => "/tmp/myapp/myapp.tmp"
Temp file of project
Default: /tmp/<PREFIX>/<PREFIX>.tmp
test => 1 test => 'on' test => 'yes'
Test mode
verbose => 1 verbose => 'on' verbose => 'yes'
Verbose mode
For internal use only (plugins). Please not call this method
my $configfile = $ctk->configfile; $ctk->configfile("/path/to/config/file.conf");
Gets and sets configfile value
my $datadir = $ctk->datadir; $ctk->datadir("/path/to/data/dir");
Gets and sets datadir value
$ctk->debug( "Message" );
Prints debug information on STDOUT if is set debug mode. Also sends message to log if log mode is enabled
$ctk->debugmode;
Returns debug flag. 1 - on, 0 - off
my $error = $ctk->error;
Returns error string if occurred any errors while creating the object
$ctk->error("error text");
Sets new error message and returns it. Also prints message on STDERR if is set debug mode and sends message to log if log mode is enabled
my $exedir = $ctk->exedir;
Gets exedir value
$ctk->load("My::Foo::Package");
Internal method for loading modules.
Returns loading status: 0 - was not loaded; 1 - was loaded
my $summary_status = $self->load_plugins( @plugins );
Loads list of plugins and returns summary status
my $logdir = $ctk->logdir; $ctk->logdir("/path/to/log/dir");
Gets and sets logdir value
my $logfile = $ctk->logfile; $ctk->logfile("/path/to/log/file.log");
Gets and sets logfile value
$ctk->logmode;
Returns log flag. 1 - on, 0 - off
my $args = $ctk->origin();
Returns hash-ref structure to all origin arguments
my $value = $ctk->option("key");
Returns option value by key
my $options = $ctk->option;
Returns hash-ref structure to all options
See "options"
my $project_name = $ctk->projtct; my $prefix = $ctk->prefix; my $suffix = $ctk->suffix;
Returns project, prefix and suffix values
my $revision = $ctk->revision;
Returns SVN revision number. Please not use it for your projects
my $my_root = $ctk->root; # /etc/<PREFIX>
Gets my root dir value
$ctk->silentmode;
Returns the verbose flag in the opposite value. 0 - verbose, 1 - silent.
See "verbosemode"
my $status = $ctk->status;
Returns boolean status of creating and using the object
my $status = $ctk->status( 1 );
Sets new status and just returns it
my $tempfile = $ctk->tempfile; $ctk->tempfile("/path/to/temp/file.tmp");
Gets and sets tempfile value
my $tempdir = $ctk->tempdir; $ctk->tempdir("/path/to/temp/dir");
Gets and sets tempdir value
$ctk->testmode;
Returns test flag. 1 - on, 0 - off
print $ctk->tms; # +0.0080 sec
Returns formatted timestamp
print $ctk->tms(1); # 0.008000
Returns NOT formatted timestamp
$ctk->verbosemode;
Returns verbose flag. 1 - on, 0 - off
See "silentmode"
use CTK qw/ WIN NULL TONULL ERR2OUT PREFIX /; use CTK qw/ :constants /
Returns string:
2>&1
Returns NULL device path or name for Windows platforms
This hash is using for sets aliases of plugins, e.g.:
use CTK qw/ %PLUGIN_ALIAS_MAP /; $PLUGIN_ALIAS_MAP{myplugin} = "My::Custom::Plugin::Module";
Return default prefix: ctk
>/dev/null 2>&1
Returns 1 if Windows platform
Will be exported following variables:
WIN, NULL, TONULL, ERR2OUT, PREFIX
%PLUGIN_ALIAS_MAP
Init version
New edition of the library
See Changes file
Changes
Config::General, JSON, JSON::XS, List::Util, MIME::Lite, Perl::OSType, Sys::Syslog, Term::ANSIColor, Text::SimpleTable, Time::Local, Try::Tiny, URI, XML::Simple, YAML, YAML::XS
See TODO file
TODO
* none noted
perl
Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2022 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.