Quiq - Weekly Travelling in CPAN
Date of Latest Release: Feb 04, 2023
Distribution: Quiq
Module version: 1.207
Main Contributors: Frank Seitz(FSEITZ)
License: The Artistic License
Source: https://github.com/s31tz/Quiq
Quiq is a "Perl class library for rapid development". The modules are "designed according to uniform principles" (translated from German).
Quiq contains 234 (Ooooops!!!) classes at the time this post is being written and their descriptions are mostly written in German.
It contains several text-based document/markup language code writers, namely Quiq::Tag (for XML), Quiq::Html::MODULES, Quiq::MediaWiki::Markup, Quiq::Css, Quiq::LaTex::MODULES; some network functionalities including Quiq::Http::MODULES, Quiq::Ssh and Quiq::Socket ; some tiny tools like Quiq::Color and Quiq::Stopwatch; some system tools like Quiq::Path, Quiq::TempFile and Quiq::Process; some modules for meta-development including Quiq::Hash and Quiq::Object; some modules for general use like Quiq::Converter, Quiq::Math and Quiq::Epoch. ...
For CSS, we have Quiq::Css :
use Quiq::Css; my $rule1 = Quiq::Css->rule('p.abstract', fontStyle => 'italic', marginLeft => '0.5cm', marginRight => '0.5cm', ); my @prop = (fontColor => 'red', textWeight => 'bold'); my $prop2 = Quiq::Css->properties(@prop); my $rule2 = Quiq::Css->rule('p.caution', @prop); my $rule2_1 = Quiq::Css->oneLine($rule2); say $rule1; say $prop2; say ""; say $rule2; say $rule2_1;Output:
p.abstract { font-style: italic; margin-left: 0.5cm; margin-right: 0.5cm; } font-color: red; text-weight: bold; p.caution { font-color: red; text-weight: bold; } p.caution { font-color: red; text-weight: bold; }
For HTML, one of the modules is Quiq::Html::Tag :
use Quiq::Html::Tag; my $str1 = $h->tag('img',src=>'URL1'); my $str2 = $h->tag('a',href=>'URL2',title=>'WEBSITE',"Link",); my $str3 = $h->tag('a',href=>'URL2', $str1); my $str4 = $h->tag('h3',"My Section"); my $str5 = $h->cat( ['doctype'], ['comment',-nl=>2,'Copyright Anonymous'], ['HTML', ['HEAD', ['TITLE','My Homepage'], ['STYLE',q| .text { color: red; } |], ], ['BODY', ['H1','Hello World!'], ['P',class=>'text',q| I am called Anonymous and this is my homepage. |], ], ] ); say $str1; say $str2; say $str3; say $str4; say $str5;The output can be easily guessed, so they are omitted here.
There are Quiq::LaTeX::Code and Quiq::TeX::Code. Here comes handy shortcut for a LaTeX document:
use Quiq::LaTeX::Document; use Quiq::LaTeX::Code; my $body = 'Hello World' ."\n\n" .'\textlang{german}{Morgen früh: Groß oder klein?}'; my $l = Quiq::LaTeX::Code->new; my $doc = Quiq::LaTeX::Document->new( language => 'english', body => $body ); say $doc->latex($l);Output:
\documentclass[english,a4paper]{scrartcl} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[utf8]{inputenc} \usepackage{babel} \usepackage{geometry} \usepackage{microtype} \geometry{height=22.5cm,bottom=3.8cm} \setlength{\parindent}{0em} \setlength{\parskip}{0.5ex} \begin{document} Hello World \textlang{german}{Morgen früh: Groß oder klein?} \end{document}
Quiq::Sql provides an easy way to write SQL queries in four different relational database systems - Oracle, PostgreSQL, SQLite, MySQL. This is especially useful for handling data types during database table creation. It also provides statement generation for common functions like SELECT, adding columns, create View , commit/rollback...
use Quiq::Sql; my $sql_o = Quiq::Sql->new('Oracle'); my $sql_m = Quiq::Sql->new('MySQL'); my $sql_l = Quiq::Sql->new('SQLite'); my $sql_p = Quiq::Sql->new('PostgreSQL'); my @t_prop = ( ['id',type=>'INTEGER',primaryKey=>1], ['name',type=>'STRING(30)'], ['alias',type=>'STRING(30)',notNull=>1], ); my $stmt1 = $sql_o->createTable('person', @t_prop); my $stmt2 = $sql_m->createTable('person', @t_prop); my $stmt3 = $sql_l->createTable('person', @t_prop); my $stmt4 = $sql_p->createTable('person', @t_prop); say $stmt1, "\n"; say $stmt2, "\n"; say $stmt3, "\n"; say $stmt4, "\n";Output:
CREATE TABLE person ( id NUMBER PRIMARY KEY , name VARCHAR2(30) , alias VARCHAR2(30) NOT NULL ) CREATE TABLE person ( id BIGINT PRIMARY KEY , name VARCHAR(30) , alias VARCHAR(30) NOT NULL ) ENGINE = InnoDB CREATE TABLE person ( id INTEGER PRIMARY KEY , name TEXT(30) , alias TEXT(30) NOT NULL ) CREATE TABLE person ( id NUMERIC PRIMARY KEY , name VARCHAR(30) , alias VARCHAR(30) NOT NULL )Another example:
use Quiq::Sql; my $sql = Quiq::Sql->new('SQLite'); my $stmt = $sql->select('user',login=>'mr_ng',password=>'5f4dcc3b5aa765d61d8327deb882cf99', -select=> qw/last_login_time created_at/); #SELECT # last_login_time # , created_at #FROM # user #WHERE # login = 'mr_ng' # AND password = '5f4dcc3b5aa765d61d8327deb882cf99'
Combining with use Quiq::Database::Api and Quiq::Udl, one can perform useful database operations.
use Quiq::Database::Api; use Quiq::Udl; use Quiq::Sql; my $udlStr = 'dbi#mysql:assignmentdb%e78783:pa55w0rd@localhost:3306'; my $sql = Quiq::Sql->new('MySQL'); my $udlObj = Quiq::Udl->new($udlStr); my $db = Quiq::Database::Api::Dbi::Connection->new($udlObj); my $stmt = $sql->select( 'bill', billnum=>'AB23571113', -select=> qw/userLname userFname billTotal/ ); my $row = $db->sql($stmt)->fetch; say join " ", $row->@*; # NG Carrie 643.4
* DBD::mysql is needed when Quiq::Database::Api is called for MySQL.
Quiq also contains some extension to Perl's idea. It names the way we write Perl hashes and arrays as "Perl Object Notation", and there are Quiq::Config utilizing it.
Quiq::Color is an utility for converting between RGB and HEX color code.
Quiq::Parallel provides a simple interface for parallel processes.
Quiq::Gimp and Quiq::ImageMagick handle the named image editor respectively.
Quiq::TreeFormatter is quite fun. It provides a staircase-like text description of trees.
use Quiq::TreeFormatter; say Quiq::TreeFormatter->new([[0,'A'],[1,'B'],[2,'C'],[3,'D']])->asText;Output:
A | +--B | +--C | +--D
To Conclude...
Having more than 1MB of source code, Quiq takes time to install. It took about 20 min to install the modules on my laptop. However, I faced some difficulties during installation. GD is an unlisted but required module. More problematic for me was that I could not install one of the dependencies Filesys::SmbClient; it had been skipped by removing Smb/Client.t and using the cpan command force install Quiq.
Some modules in Quiq contains certain originality and it has been a great effort to design and write them, so I think Quiq is worth to be introduced. Other CPAN authors may get inspiration from these modules, or consider making a merge/push request to the Quiq library on GitHub.
Leave a comment