The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CTK::Util - CTK Utilities

VERSION

Version 1.00

REVISION

$Revision: 97 $

SYNOPSIS

    use CTK::Util;
    use CTK::Util qw( :ALL ); # Export only ALL tag. See TAGS section
    
    my @ls = ls(".");
    
    # or (for CTK module)
    
    use CTK;
    my @ls = CTK::ls(".");
    
    # or (for core and extended subroutines only)
    
    use CTK;
    my $c = new CTK;
    my $prefix = $c->getsyscfg("prefix");
    

DESCRIPTION

Public subroutines

SUBROUTINES

...

eqtime

    eqtime("source/file", "destination/file");

Sets modified time of destination to that of source.

escape

    $safe = escape("10% is enough\n");
    

Replaces each unsafe character in the string "10% is enough\n" with the corresponding escape sequence and returns the result. The string argument should be a string of bytes.

See also URI::Escape

shuffle

    @cards = shuffle(0..51); # 0..51 in a random order

Returns the elements of LIST in a random order

Pure-Perl implementation of Function List::Util::PP::shuffle (Copyright (c) 1997-2009 Graham Barr <gbarr@pobox.com>. All rights reserved.)

See also List::Util

touch

    touch("file");

Makes file exist, with current timestamp

UTILITY SUBROUTINES

sendmail, send_mail

    my $sent = sendmail(
        -to       => 'to@example.com',
        -cc       => 'cc@example.com',     ### OPTIONAL
        -from     => 'from@example.com',
        -subject  => 'my subject',
        -message  => 'my message',
        -type     => 'text/plain',
        -sendmail => '/usr/sbin/sendmail', ### OPTIONAL
        -charset  => 'windows-1251',
        -flags    => '-t',                 ### OPTIONAL
        -smtp     => '192.168.1.1',        ### OPTIONAL
        -authuser => '',                   ### OPTIONAL
        -authpass => '',                   ### OPTIONAL
        -attach   => [                     ### OPTIONAL
            { 
                Type=>'text/plain', 
                Data=>'document 1 content', 
                Filename=>'doc1.txt', 
                Disposition=>'attachment',
            },
            {
                Type=>'text/plain', 
                Data=>'document 2 content', 
                Filename=>'doc2.txt', 
                Disposition=>'attachment',
            },
            {
                Type=>'text/html', 
                Data=>'blah-blah-blah', 
                Filename=>'response.htm', 
                Disposition=>'attachment',
            },
            {
                Type=>'image/gif', 
                Path=>'aaa000123.gif',
                Filename=>'logo.gif', 
                Disposition=>'attachment',
            },
            ### ... ###
          ],
    );
    debug($sent ? 'mail has been sent :)' : 'mail was not sent :(');

unescape

    $str = unescape(escape("10% is enough\n"));
    

Returns a string with each %XX sequence replaced with the actual byte (octet).

This does the same as:

    $string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;

See also URI::Escape

EXTENDED SUBROUTINES

cachedir

    my $value = cachedir();
    my $value = $c->cachedir();

For example value can be set as: /var/cache

/var/cache is intended for cached data from applications. Such data is locally generated as a result of time-consuming I/O or calculation. The application must be able to regenerate or restore the data. Unlike /var/spool, the cached files can be deleted without data loss. The data must remain valid between invocations of the application and rebooting the system.

Files located under /var/cache may be expired in an application specific manner, by the system administrator, or both. The application must always be able to recover from manual deletion of these files (generally because of a disk space shortage). No other requirements are made on the data format of the cache directories.

See http://www.pathname.com/fhs/pub/ and Sys::Path cachedir

docdir

    my $value = docdir();
    my $value = $c->docdir();
    

For example value can be set as: /usr/share/doc

See <Sys::Path> docdir

localstatedir

    my $value = localstatedir();
    my $value = $c->localstatedir();

For example value can be set as: /var

/var - $Config::Config{'prefix'}

/var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files. Some portions of /var are not shareable between different systems. For instance, /var/log, /var/lock, and /var/run. Other portions may be shared, notably /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news.

/var is specified here in order to make it possible to mount /usr read-only. Everything that once went into /usr that is written to during system operation (as opposed to installation and software maintenance) must be in /var. If /var cannot be made a separate partition, it is often preferable to move /var out of the root partition and into the /usr partition. (This is sometimes done to reduce the size of the root partition or when space runs low in the root partition.) However, /var must not be linked to /usr because this makes separation of /usr and /var more difficult and is likely to create a naming conflict. Instead, link /var to /usr/var.

Applications must generally not add directories to the top level of /var. Such directories should only be added if they have some system-wide implication, and in consultation with the FHS mailing list.

See http://www.pathname.com/fhs/pub/ and Sys::Path localstatedir

localedir

    my $value = localedir();
    my $value = $c->localedir();

For example value can be set as: /usr/share/locale

See Sys::Path localedir

lockdir

    my $value = lockdir();
    my $value = $c->lockdir();

For example value can be set as: /var/lock

Lock files should be stored within the /var/lock directory structure. Lock files for devices and other resources shared by multiple applications, such as the serial device lock files that were originally found in either /usr/spool/locks or /usr/spool/uucp, must now be stored in /var/lock. The naming convention which must be used is "LCK.." followed by the base name of the device. For example, to lock /dev/ttyS0 the file "LCK..ttyS0" would be created. 5

The format used for the contents of such lock files must be the HDB UUCP lock file format. The HDB format is to store the process identifier (PID) as a ten byte ASCII decimal number, with a trailing newline. For example, if process 1230 holds a lock file, it would contain the eleven characters: space, space, space, space, space, space, one, two, three, zero, and newline.

See http://www.pathname.com/fhs/pub/ and Sys::Path lockdir

prefixdir

    my $value = prefixdir();
    my $value = $c->prefixdir();

For example value can be set as: /usr

/usr - $Config::Config{'prefix'}

Is a helper function and should not be used directly.

/usr is the second major section of the filesystem. /usr is shareable, read-only data. That means that /usr should be shareable between various FHS-compliant hosts and must not be written to. Any information that is host-specific or varies with time is stored elsewhere.

Large software packages must not use a direct subdirectory under the /usr hierarchy.

See http://www.pathname.com/fhs/pub/ and Sys::Path prefix

rundir

    my $value = rundir();
    my $value = $c->rundir();

For example value can be set as: /var/run

This directory contains system information data describing the system since it was booted. Files under this directory must be cleared (removed or truncated as appropriate) at the beginning of the boot process. Programs may have a subdirectory of /var/run; this is encouraged for programs that use more than one run-time file. 7 Process identifier (PID) files, which were originally placed in /etc, must be placed in /var/run. The naming convention for PID files is <program-name>.pid. For example, the crond PID file is named /var/run/crond.pid.

See http://www.pathname.com/fhs/pub/ and Sys::Path rundir

sharedir

    my $value = sharedir();
    my $value = $c->sharedir();

For example value can be set as: /usr/share

The /usr/share hierarchy is for all read-only architecture independent data files. 10 This hierarchy is intended to be shareable among all architecture platforms of a given OS; thus, for example, a site with i386, Alpha, and PPC platforms might maintain a single /usr/share directory that is centrally-mounted. Note, however, that /usr/share is generally not intended to be shared by different OSes or by different releases of the same OS.

Any program or package which contains or requires data that doesn’t need to be modified should store that data in /usr/share (or /usr/local/share, if installed locally). It is recommended that a subdirectory be used in /usr/share for this purpose.

Game data stored in /usr/share/games must be purely static data. Any modifiable files, such as score files, game play logs, and so forth, should be placed in /var/games.

See http://www.pathname.com/fhs/pub/ and Sys::Path datadir

sharedstatedir

    my $value = sharedstatedir();
    my $value = $c->sharedstatedir();

For example value can be set as: /var/lib

This hierarchy holds state information pertaining to an application or the system. State information is data that programs modify while they run, and that pertains to one specific host. Users must never need to modify files in /var/lib to configure a package’s operation.

State information is generally used to preserve the condition of an application (or a group of inter-related applications) between invocations and between different instances of the same application. State information should generally remain valid after a reboot, should not be logging output, and should not be spooled data.

An application (or a group of inter-related applications) must use a subdirectory of /var/lib for its data. There is one required subdirectory, /var/lib/misc, which is intended for state files that don’t need a subdirectory; the other subdirectories should only be present if the application in question is included in the distribution.

/var/lib/<name> is the location that must be used for all distribution packaging support. Different distributions may use different names, of course.

See http://www.pathname.com/fhs/pub/ and Sys::Path sharedstatedir

spooldir

    my $value = spooldir();
    my $value = $c->spooldir();

For example value can be set as: /var/spool

/var/spool contains data which is awaiting some kind of later processing. Data in /var/spool represents work to be done in the future (by a program, user, or administrator); often data is deleted after it has been processed.

See http://www.pathname.com/fhs/pub/ and Sys::Path spooldir

srvdir

    my $value = srvdir();
    my $value = $c->srvdir();

For example value can be set as: /srv

/srv contains site-specific data which is served by this system.

See http://www.pathname.com/fhs/pub/ and Sys::Path srvdir

sysconfdir

    my $value = sysconfdir();
    my $value = $c->sysconfdir();

For example value can be set as: /etc

The /etc hierarchy contains configuration files. A "configuration file" is a local file used to control the operation of a program; it must be static and cannot be an executable binary.

See http://www.pathname.com/fhs/pub/ and Sys::Path sysconfdir

syslogdir

    my $value = syslogdir();
    my $value = $c->syslogdir();

For example value can be set as: /var/log

This directory contains miscellaneous log files. Most logs must be written to this directory or an appropriate subdirectory.

See http://www.pathname.com/fhs/pub/ and Sys::Path logdir

webdir

    my $value = webdir();
    my $value = $c->webdir();

For example value can be set as: /var/www

Directory where distribution put static web files.

See Sys::Path webdir

CORE SUBROUTINES

carp, croak, cluck, confess

This is the Carp functions, and exported here for historical reasons.

carp

Warn user (from perspective of caller)

    carp "string trimmed to 80 chars";
croak

Die of errors (from perspective of caller)

    croak "We're outta here!";
cluck

Warn user (more detailed what carp with stack backtrace)

    cluck "This is how we got here!";
confess

Die of errors with stack backtrace

    confess "not implemented";

getsyscfg, syscfg

Returns all hash %Config from system module Config or one value of this hash

    my %syscfg = getsyscfg();
    my $prefix = getsyscfg("prefix");
    # or
    my %syscfg = $c->getsyscfg();
    my $prefix = $c->getsyscfg("prefix");

See Config module for details

isos

Returns true or false if the OS name is of the current value of $^O

    isos('mswin32') ? "OK" : "NO";
    # or
    $c->isos('mswin32') ? "OK" : "NO";
    

See Perl::OSType for details

isostype

Given an OS type and OS name, returns true or false if the OS name is of the given type.

    isostype('Windows') ? "OK" : "NO";
    isostype('Unix', 'dragonfly') ? "OK" : "NO";
    # or
    $c->isos('Windows') ? "OK" : "NO";
    $c->isostype('Unix', 'dragonfly') ? "OK" : "NO";

See Perl::OSType is_os_type

read_attributes

Smart rearrangement of parameters to allow named parameter calling. We do the rearrangement if the first parameter begins with a -

    my @args = @_;
    my ($content, $maxcnt, $timeout, $timedie, $base, $login, $password, $host, $table_tmp);
    ($content, $maxcnt, $timeout, $timedie, $base, $login, $password, $host, $table_tmp) =
    read_attributes([
        ['DATA','CONTENT','USERDATA'],
        ['COUNT','MAXCOUNT','MAXCNT'],
        ['TIMEOUT','FORBIDDEN','INTERVAL'],
        ['TIMEDIE','TIME'],
        ['BD','DB','BASE','DATABASE'],
        ['LOGIN','USER'],
        ['PASSWORD','PASS'],
        ['HOST','HOSTNAME','ADDRESS','ADDR'],
        ['TABLE','TABLENAME','NAME','SESSION','SESSIONNAME']
    ],@args) if defined $args[0];

See CGI::Util

TAGS

ALL, DEFAULT

Export all subroutines, default

BASE

Export only base subroutines

FORMAT

Export only text format subroutines

DATE

Export only date and time subroutines

FILE

Export only file and directories subroutines

UTIL

Export only utility subroutines

ATOM

Export only processing subroutines

API

Export only inerface subroutines

SEE ALSO

MIME::Lite, CGI::Util, Time::Local, Net::FTP, IPC::Open3, List::Util

AUTHOR

Serz Minus (Lepenkov Sergey) http://serzik.ru <minus@mail333.com>

COPYRIGHT

Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms and conditions as Perl itself.

This program is distributed under the GNU LGPL v3 (GNU Lesser General Public License version 3).

See LICENSE file

1 POD Error

The following errors were encountered while parsing the POD:

Around line 267:

Non-ASCII character seen before =encoding in 'doesn’t'. Assuming CP1252