Konstrukt::Lib - Common function library
$Konstrukt::Lib->some_handy_method($param); #see documentation for each method
This is a collection of commonly used methods. For more information take a look at the documentation for each method.
You may do some configuration in your konstrukt.settings to let the mail method know how it should work:
#transport: #currently available: sendmail, smtp. #defaults to 'sendmail'. mail/transport sendmail #the path of your mailer: #you may also specify some extra parameters. #defaults to 'sendmail'. mail/sendmail/path /usr/sbin/sendmail -odb #your smtp server: #defaults to 'localhost'. mail/smtp/server some.smtp-server.com #user and pass: #optional. when no user/pass is given, no auth will be tried. #defaults to 'undefined' mail/smtp/user your username mail/smtp/pass your password #smtp authentication mechanism: #optional. may be: CRAM-MD5, NTLM, LOGIN, PLAIN. #when not specified every available method will be tried. mail/smtp/authtype CRAM-MD5 #defaults for the sender identification. #will be used when you don't specifiy it in your code. #defaults: mail/default_from mail@localhost mail/default_name Konstrukt Framework
Constructor of this class
Initialization of this class
Escapes some critical sh characters
$string - Unescaped string
Converts \n-separated texts into to <p></p>-separated text.
Escapes some critical HTML characters
Unescapes some critical HTML characters
$string - Escaped string
Encode a string into a sequence of hex-values as done in HTTP URIs.
Encodes every character but [0-9A-Za-z-_.!~*'()]. If the $enc_all parameter is true, all characters will be encoded.
$string - String to encode
$enc_all - Encode all characters
Escapes some critical XML characters
$text - Unescaped string
$esc_all - Boolean. Shall all chars besides letters and numbers be escaped?
Converts \r?\n to <br />\n
Send out an email using the "sendmail" app on your system or directly via SMTP. You may specify some settings in your konstrukt.settings. See above.
Uses Mail::Sender for SMTP, which in turn uses Digest::HMAC_MD5 for auth type CRAM-MD5 and Authen::NTLM for auth type NTLM. So you might want to install those modules, if you use these auth types.
CRAM-MD5
$subject - The mail's subject
$text - The body
$to - The recipient
($cc) - Optional: Carbon copy
($bcc) - Optional: Blind carbon copy
($from) - The senders email address (e.g. john@doe.com). If not specified the defaults from your settings will be used.
($FROM) - The sender full name (e.g. "John Doe") If not specified the defaults from your settings will be used.
Send out an email using the "sendmail" app on your system. Generally only used internally. You probably want to use "mail".
Send out an email using an SMTP server. Generally only used internally. You probably want to use "mail".
Generates a random password consisting of characters and digits of a given length.
$length - The passwords length
$lowercase - Optional: Only use lowercase letters. Defaults to 0.
Returns the specified local time in the w3c date/time format. Actually, it's ISO 8601. Returns the diffence in the format as specified in http://www.w3.org/TR/NOTE-datetime YYYY-MM-DDThh:mm:ssTZD
$year - Either the years since 1900 (e.g. 1996 = 96, 2004 = 104) or the absolute year (e.g. 1996)
$month - Jan = 1, Feb = 2, ...
$mday - 1,2,3,...
$hour
$minute
$second
Returns the specified local time in the date/time format specified in RFC 822: Day, DD Mon YYYY hh:mm:ss TZD
May be used to do the installation work of a DBI backend of some plugins.
The backend modules themselves pass a string containing SQL-statements (among others) to create the needed tables.
The section for the creation is named dbi: create. The section must be declared using the scheme described in "extract_data_sections".
dbi: create
The statements in each block are separated through semicolons.
Example:
-- 8< -- dbi: create -- >8 -- CREATE TABLE IF NOT EXISTS foo ( <definition> ); CREATE TABLE IF NOT EXISTS bar ( <definition> );
The backend plugin stores these SQL-statements in it's __DATA__-section at the end of the file.
__DATA__
The install method of the backend module then can get as simple as:
install
sub install { my ($self) = @_; return $Konstrukt::Lib->plugin_dbi_install_helper($self->{db_settings}); }
This method returns true on success.
Parameters:
$db - Either an array reference containing the DBI source, user and password of the database your backend uses or a database handle to this db.
May be used to do the installation work of the necessary files (like templates or images) of some plugins.
The section for the each text file (e.g. a template) is named textfile: subfolder/name.extension. The section must be declared using the scheme described in "extract_data_sections". The section for a binary file must be named binaryfile: subfolder/name.extension. The content of the binary file must be base64 encoded and put into the section. (You can use the supplied script base64enc.pl which reads from STDIN and writes the encoded data to STDOUT.)
textfile: subfolder/name.extension
binaryfile: subfolder/name.extension
base64enc.pl
The path/filename of template files should follow this scheme:
<template type>/<name of the template>.template
template type should be used to group different types of templates. This may be:
template type
layout: Templates to display the data
messages: Templates to display messages like errors (e.g. "permission denied") and confirmations (e.g. "entry successfully created")
Of course you can use other "directory names".
If the filename starts with a slash (/), the path will not be prepended by the basepath. It will be put into the document root.
/
-- 8< -- textfile: layout/display.template -- >8 -- This is the data: <+$ data $+>(no data specified)<+$ / $+> -- 8< -- textfile: layout/display_something_else.template -- >8 -- -- 8< -- binaryfile: /gfx/some_icon.gif -- >8 -- R0lGODlhEAAQAKIAAEuVzf+MO////v96G/fMrdDj8v/izf+1fyH5BAAAAAAALAAAAAAQABAAAANE KLrcziQMOZ8gI2sCOliYNhmC9wmHWCkmqh6MGWpw7M0D4cgi2fCi2qKVCto6iqIm4GspcCNBYVpg GFQ5i8AgoQy0jwQAOw== ...
The plugin stores these files in it's __DATA__-section at the end of the file.
The install method of the plugin then can get as simple as:
sub install { my ($self) = @_; return $Konstrukt::Lib->plugin_file_install_helper($self->{template_path}); }
$basepath - The base path for all the files of your plugin.
Some plugins store some additional data at the end (after __DATA__) of the module file.
This method takes all this data and returns multiple sections of this data (which might represent some files or SQL statements and the like) as an hash:
{ name_of_section1 => 'content1', name_of_section2 => 'content2', ... }
Where the text after __DATA__ is organized like that:
-- 8< -- name_of_section1 -- >8 -- content1 -- 8< -- name_of_section2 -- >8 -- content2
The sections have to be separated by "-- 8< --" followed by the identifier of the section followed by "-- >8 --" all on one line.
$package - The name of the package whose __DATA__ section should be read and parsed
Encrypt/Decrypt a string with a defined key using XOR encryption.
$text - String to en-/decrypt
$key - The key to use for en-/decryption
Splits a given string into word. Multiple words which are surrounded by doublequotes will be parsed into one word.
Returns an array of words/word sequences.
$string - String to parse
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.
Konstrukt
To install Konstrukt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Konstrukt
CPAN shell
perl -MCPAN -e shell install Konstrukt
For more information on module installation, please visit the detailed CPAN module installation guide.