RiveScript::Tutorial 1.02
Programming -> Libraries
0.20MB
Perl Artistic License
Show Detail
RiveScript::Tutorial is a beginners guide to creating their first RiveScript brain.
This tutorial outlines the various capabilities of the RiveScript specification and offers some recommended pointers for creating a well-formed RiveScript brain. What you do with this knowledge is up to you; be creative!
Be sure to skim over the RiveScript manpage first, because this tutorial jumps right in to using the various RiveScript commands without always explaining what each of them do.
A Simple RiveScript Interpreter
Here is a simple Perl script for running a RiveScript interpreter. This assumes that the brains RS files will be stored in a directory called "tutorial", local to the Perl script. Youd want to edit certain parameters in this code if you see fit.
#!/usr/bin/perl -w
use strict;
use warnings;
use RiveScript;
# Create the RiveScript interpreter.
my $rive = new RiveScript();
# Load the RS tutorial brain.
$rive->loadDirectory ("./tutorial");
# Sort them.
$rive->sortReplies;
# Go into a chatting loop.
while (1) {
print "User> ";
my $msg = ;
chomp $msg;
# Grab a reply.
my @reply = $rive->reply (user,$msg);
print " Bot> $_n" foreach(@reply);
}
This tutorial outlines the various capabilities of the RiveScript specification and offers some recommended pointers for creating a well-formed RiveScript brain. What you do with this knowledge is up to you; be creative!
Be sure to skim over the RiveScript manpage first, because this tutorial jumps right in to using the various RiveScript commands without always explaining what each of them do.
A Simple RiveScript Interpreter
Here is a simple Perl script for running a RiveScript interpreter. This assumes that the brains RS files will be stored in a directory called "tutorial", local to the Perl script. Youd want to edit certain parameters in this code if you see fit.
#!/usr/bin/perl -w
use strict;
use warnings;
use RiveScript;
# Create the RiveScript interpreter.
my $rive = new RiveScript();
# Load the RS tutorial brain.
$rive->loadDirectory ("./tutorial");
# Sort them.
$rive->sortReplies;
# Go into a chatting loop.
while (1) {
print "User> ";
my $msg = ;
chomp $msg;
# Grab a reply.
my @reply = $rive->reply (user,$msg);
print " Bot> $_n" foreach(@reply);
}
2
Programming -> Libraries
1.4MB
Perl Artistic License
Show Detail
Prima::tutorial is an introductory tutorial.
Programming graphic interfaces is often considered somewhat boring, and not without a cause. It is a small pride in knowing that your buttons and scrollbars work exactly as millions of others buttons and scrollbars do, so whichever GUI toolkit is chosen, it is usually regarded as a tool of small importance, and the less obtrusive, the better.
Given that, and trying to live up to the famous Perl making easy things easy and hard things possible mantra, this manual page is an introductory tutorial meant to show how to write easy things easy. The hard things are explained in the other Prima manual pages ( see Prima ).
Programming graphic interfaces is often considered somewhat boring, and not without a cause. It is a small pride in knowing that your buttons and scrollbars work exactly as millions of others buttons and scrollbars do, so whichever GUI toolkit is chosen, it is usually regarded as a tool of small importance, and the less obtrusive, the better.
Given that, and trying to live up to the famous Perl making easy things easy and hard things possible mantra, this manual page is an introductory tutorial meant to show how to write easy things easy. The hard things are explained in the other Prima manual pages ( see Prima ).
3
Programming -> Libraries
0.21MB
Perl Artistic License
Show Detail
yagg::Tutorial is a Perl module that contains a tutorial for yagg.
SYNOPSIS
# To use the generator
./yagg -m nonterminals.yg terminals.lg
./output/progs/generate 5
This tutorial will show you how to use yagg, by way of two examples. In the first example, we create a simple logical expression generator from scratch. In the second example, we create a more sophisticated logical expression generator from existing parser/lexer input files, such as those used by YACC/Bison and LEX/FLEX. These examples, plus another more sophisticated fault tree generator are included with the distribution in the examples/ directory.
It is assumed that the reader knows a little about formal grammars. Ideally, the reader would have some experience writing grammars for input to parser generators like YACC and Bison.
SYNOPSIS
# To use the generator
./yagg -m nonterminals.yg terminals.lg
./output/progs/generate 5
This tutorial will show you how to use yagg, by way of two examples. In the first example, we create a simple logical expression generator from scratch. In the second example, we create a more sophisticated logical expression generator from existing parser/lexer input files, such as those used by YACC/Bison and LEX/FLEX. These examples, plus another more sophisticated fault tree generator are included with the distribution in the examples/ directory.
It is assumed that the reader knows a little about formal grammars. Ideally, the reader would have some experience writing grammars for input to parser generators like YACC and Bison.
4
Programming -> Libraries
0.024MB
Perl Artistic License
Show Detail
Tkx::Tutorial Perl module contains a tutorial about how to use Tkx.
Tk is a toolkit that allows you to create applications with graphical interfaces for Windows, Mac OS X and X11. The Tk toolkit is native to the Tcl programming language, but its ease of use and cross-platform availability has made it the GUI toolkit of choice for many other dynamic languages as well.
Tkx is a Perl module that makes the Tk toolkit available to Perl programs. By loading the Tkx module Perl programs can create windows and fill them with text, images, buttons and other controls that make up the user interface of the application.
Hello World
Lets start with the mandatory exercise of creating an application that greats the world. Here we make the application window contain a single button which will shut down the application if clicked. The code to make this happen is:
use Tkx;
Tkx::button(".b",
-text => "Hello, world",
-command => sub { Tkx::destroy("."); },
);
Tkx::pack(".b");
Tkx::MainLoop()
Save this to a file called hello.pl and then run perl hello.pl to start up the application. A window with the text "Hello, world" should appear on your screen.
After the Tkx module has been loaded by the use Tkx statement the application will show an empty window called ".". We create a button with the name ".b" and tell the window to display the button with the call to Tkx::pack(). After the layout of the window has been set up we need to pass control back to Tk so that it can draw the window and invoke our callback if the button is clicked. This is achieved by the Tkx::MainLoop() call at the end. Clicking the button will invoke the subroutine registered with the -command option of the button. In this case the callback simply destroys the window, which in turn will terminate the application.
Tk is a toolkit that allows you to create applications with graphical interfaces for Windows, Mac OS X and X11. The Tk toolkit is native to the Tcl programming language, but its ease of use and cross-platform availability has made it the GUI toolkit of choice for many other dynamic languages as well.
Tkx is a Perl module that makes the Tk toolkit available to Perl programs. By loading the Tkx module Perl programs can create windows and fill them with text, images, buttons and other controls that make up the user interface of the application.
Hello World
Lets start with the mandatory exercise of creating an application that greats the world. Here we make the application window contain a single button which will shut down the application if clicked. The code to make this happen is:
use Tkx;
Tkx::button(".b",
-text => "Hello, world",
-command => sub { Tkx::destroy("."); },
);
Tkx::pack(".b");
Tkx::MainLoop()
Save this to a file called hello.pl and then run perl hello.pl to start up the application. A window with the text "Hello, world" should appear on your screen.
After the Tkx module has been loaded by the use Tkx statement the application will show an empty window called ".". We create a button with the name ".b" and tell the window to display the button with the call to Tkx::pack(). After the layout of the window has been set up we need to pass control back to Tk so that it can draw the window and invoke our callback if the button is clicked. This is achieved by the Tkx::MainLoop() call at the end. Clicking the button will invoke the subroutine registered with the -command option of the button. In this case the callback simply destroys the window, which in turn will terminate the application.
5
Programming -> Libraries
0.83MB
Perl Artistic License
Show Detail
Imager::Tutorial is an introduction to Imager.
Before you start
If you have the necessary knowledge, install the image format libraries you want Imager image file support for, and Imager itself, otherwise arrange to have it done.
You will also want some sort of image viewer tool, whether an image editor like Photoshop or the GIMP, or a web browser.
Hello Boxes! - A Simple Start
As with any perl program its useful to start with a #! line, and to enable strict mode:
#!/usr/bin/perl -w
# you might to use warnings; instead of the -w above
use strict;
These lines will be omitted in further examples.
As with any module, you need to load it:
use Imager;
Now create a image to draw on:
my $image = Imager->new(xsize => 100, ysize => 100);
and draw a couple of filled rectangles on it:
$image->box(xmin => 0, ymin => 0, xmax => 99, ymax => 99,
filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);
Since the first box fills the whole image, it can be simplified to:
$image->box(filled => 1, color => blue);
and save it to a file:
$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;
So our completed program is:
use Imager;
my $image = Imager->new(xsize => 100, ysize => 100);
$image->box(filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);
$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;
Before you start
If you have the necessary knowledge, install the image format libraries you want Imager image file support for, and Imager itself, otherwise arrange to have it done.
You will also want some sort of image viewer tool, whether an image editor like Photoshop or the GIMP, or a web browser.
Hello Boxes! - A Simple Start
As with any perl program its useful to start with a #! line, and to enable strict mode:
#!/usr/bin/perl -w
# you might to use warnings; instead of the -w above
use strict;
These lines will be omitted in further examples.
As with any module, you need to load it:
use Imager;
Now create a image to draw on:
my $image = Imager->new(xsize => 100, ysize => 100);
and draw a couple of filled rectangles on it:
$image->box(xmin => 0, ymin => 0, xmax => 99, ymax => 99,
filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);
Since the first box fills the whole image, it can be simplified to:
$image->box(filled => 1, color => blue);
and save it to a file:
$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;
So our completed program is:
use Imager;
my $image = Imager->new(xsize => 100, ysize => 100);
$image->box(filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);
$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;
6
Programming -> Libraries
0.76MB
Perl Artistic License
Show Detail
Template::Tutorial are template toolkit tutorials.
This section includes tutorials on using the Template Toolkit. Subjects currently include an general overview of the Template Toolkit, showing users how to get quickly up to speed building web content, and a tutorial on generating and using data files, with particular reference to XML.
Template::Tutorial::Web
Generating Web Content Using the Template Toolkit
This tutorial provides an introduction to the Template Toolkit and a "quick start" guide to getting up to speed. Its primarily focus is on using the Template Toolkit to build web content and it covers 4 basic areas: using tpage and ttree; using the Template.pm module in CGI scripts; writing Apache/mod_perl handlers; and extending the toolkit by writing plugins.
Template::Tutorial::Datafile
Creating Data Output Files Using the Template Toolkit
This tutorial gives an overview of the Template Toolkit, showing in particular how to use it to read and write data files in various different formats and styles. It was written by Dave Cross and first appeared as a lead article at http://www.perl.com/ earlier in the year (2001).
This section includes tutorials on using the Template Toolkit. Subjects currently include an general overview of the Template Toolkit, showing users how to get quickly up to speed building web content, and a tutorial on generating and using data files, with particular reference to XML.
Template::Tutorial::Web
Generating Web Content Using the Template Toolkit
This tutorial provides an introduction to the Template Toolkit and a "quick start" guide to getting up to speed. Its primarily focus is on using the Template Toolkit to build web content and it covers 4 basic areas: using tpage and ttree; using the Template.pm module in CGI scripts; writing Apache/mod_perl handlers; and extending the toolkit by writing plugins.
Template::Tutorial::Datafile
Creating Data Output Files Using the Template Toolkit
This tutorial gives an overview of the Template Toolkit, showing in particular how to use it to read and write data files in various different formats and styles. It was written by Dave Cross and first appeared as a lead article at http://www.perl.com/ earlier in the year (2001).
7
Programming -> Libraries
0.19MB
Perl Artistic License
Show Detail
PAR::Tutorial is a cross-platform Packaging and Deployment with PAR.
SYNOPSIS
This is a tutorial on PAR, first appeared at the 7th Perl Conference. The HTML version of this tutorial is available online as http://aut.dyndns.org/par-tutorial/.
On Deploying Perl Applications
% sshnuke.pl 10.2.2.2 -rootpw="Z1ON0101"
Perl v5.6.1 required--this is only v5.6.0, stopped at sshnuke.pl line 1.
BEGIN failed--compilation aborted at sshnuke.pl line 1.
Q: "Help! I cant run your program!"
A1: Install Perl & perl -MCPAN -einstall(...)
How do we know which modules are needed?
New versions of CPAN modules may break sshnuke.pl
A2: Install Perl & tar zxf my_perllib.tgz
Possibly overwriting existing modules; not cross-platform at all
A3: Use the executable generated by perlcc sshnuke.pl
Impossible to debug; perlcc usually does not work anyway
SYNOPSIS
This is a tutorial on PAR, first appeared at the 7th Perl Conference. The HTML version of this tutorial is available online as http://aut.dyndns.org/par-tutorial/.
On Deploying Perl Applications
% sshnuke.pl 10.2.2.2 -rootpw="Z1ON0101"
Perl v5.6.1 required--this is only v5.6.0, stopped at sshnuke.pl line 1.
BEGIN failed--compilation aborted at sshnuke.pl line 1.
Q: "Help! I cant run your program!"
A1: Install Perl & perl -MCPAN -einstall(...)
How do we know which modules are needed?
New versions of CPAN modules may break sshnuke.pl
A2: Install Perl & tar zxf my_perllib.tgz
Possibly overwriting existing modules; not cross-platform at all
A3: Use the executable generated by perlcc sshnuke.pl
Impossible to debug; perlcc usually does not work anyway
8
Programming -> Libraries
0.048MB
Perl Artistic License
Show Detail
Games::ScottAdams::Tutorial is a Perl module with the Scott Adams Adventure Compiler Tutorial.
INTRODUCTION
This document walks you through the process of creating a small but complete and playable game with six rooms, seven items including a single treasure, and a couple of puzzles.
It makes no attempt to be complete: you need the reference manual for that. But by the time youve worked your way through this tutorial you should be familiar with rooms, items, actions and occurrences, and youll be ready to start writing your own games.
INTRODUCTION
This document walks you through the process of creating a small but complete and playable game with six rooms, seven items including a single treasure, and a couple of puzzles.
It makes no attempt to be complete: you need the reference manual for that. But by the time youve worked your way through this tutorial you should be familiar with rooms, items, actions and occurrences, and youll be ready to start writing your own games.
9
System -> Networking
9.0MB
FDL GNU Free Documentation License
Show Detail
IPTables-tutorials aim is to explain iptables in a complete and simple way. The iptables-tutorial is currently rather stable, and contains information on all the currently available matches and targets (in kernel), as well as a couple of complete example scripts and explanations. It contains a complete section on iptables syntax, as well as other interesting commands such as iptables-save and iptables-restore.
The tutorial has recently been under heavy scrutiny and updating, as can be seen in this, the latest version of the tutorial. It is now also available in bookform from Lulu.com. If you feel like contributing or donating to the author of this tutorial, please do buy the book! Thank you!
If you need help, you are better off by asking the netfilter mailing list which you can reach at netfilter at lists.netfilter.org. For more information on this, visit the netfilter mailinglist page. You may also contact the linuxsecurity mailing list at security-discuss AT linuxsecurity dotcom. Both are fairly large, and should be able to help you much much better than I can.
The tutorial has recently been under heavy scrutiny and updating, as can be seen in this, the latest version of the tutorial. It is now also available in bookform from Lulu.com. If you feel like contributing or donating to the author of this tutorial, please do buy the book! Thank you!
If you need help, you are better off by asking the netfilter mailing list which you can reach at netfilter at lists.netfilter.org. For more information on this, visit the netfilter mailinglist page. You may also contact the linuxsecurity mailing list at security-discuss AT linuxsecurity dotcom. Both are fairly large, and should be able to help you much much better than I can.
10
Programming -> Libraries
0.13MB
Perl Artistic License
Show Detail
PDF::Reuse::Tutorial is a Perl module that will teach you how to produce PDF-files with PDF::Reuse.
In this tutorial I will show some aspects of PDF::Reuse, so you should be able to use it in your own programs. Most important is how to produce and reuse PDF-code, and then if you are interested, you can look at Graphics and JavaScript, so you can to do special things.
Reusing code:
You can take advantage of what has been done before, it is not necessary to start from scratch every time you create a PDF-file. You use old PDF-files as a source for forms, images, fonts and texts. The components are taken as they are, or rearranged, and you add your own texts and you produce new output.
If you dont care too much about the size of your templates, you should make them with a commercial, visual tool, thats most practical; and then you should use PDF::Reuse to mass produce your files. In this tutorial I show in many places how create single files with PDF::Reuse. That is possible, but more of an exception. I do it here to show the technique. You will anyway need it to add texts and graphics to your templates.
Graphics:
With this module you get a good possibility to program directly with the basic graphic operators of PDF. This is perhaps an advanced level, and you can avoid it if you want. On the other hand, it is not very difficult, and if you take advantage of it, your possibilities to manage text and graphics increase very much. You should look at the "PDF-reference manual" which probably is possible to download from http://partners.adobe.com/asn/developer/acrosdk/docs.html. Look especially at chapter 4 and 5, Graphics and Text, and the Operator summary.
Whenever the function prAdd() is used in this tutorial, you can probably get more explanations in the "PDF-reference manual". The code, you add to the content stream with prAdd(), has to follow the PDF syntax completely.
JavaScript:
You can add JavaScript to your PDF-file programmatically. This works with Acrobat Reader 5.0.5 or Acrobat 5.0 and higher versions.
You should have the "Acrobat JavaScript Object Specification" by hand. If you havent got Acrobat, you can probably download it from http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html. It is technical note # 5186. JavaScript for HTML and PDF differs so much that you need the manual, even if you know JavaScript very well.
In this tutorial I will show some aspects of PDF::Reuse, so you should be able to use it in your own programs. Most important is how to produce and reuse PDF-code, and then if you are interested, you can look at Graphics and JavaScript, so you can to do special things.
Reusing code:
You can take advantage of what has been done before, it is not necessary to start from scratch every time you create a PDF-file. You use old PDF-files as a source for forms, images, fonts and texts. The components are taken as they are, or rearranged, and you add your own texts and you produce new output.
If you dont care too much about the size of your templates, you should make them with a commercial, visual tool, thats most practical; and then you should use PDF::Reuse to mass produce your files. In this tutorial I show in many places how create single files with PDF::Reuse. That is possible, but more of an exception. I do it here to show the technique. You will anyway need it to add texts and graphics to your templates.
Graphics:
With this module you get a good possibility to program directly with the basic graphic operators of PDF. This is perhaps an advanced level, and you can avoid it if you want. On the other hand, it is not very difficult, and if you take advantage of it, your possibilities to manage text and graphics increase very much. You should look at the "PDF-reference manual" which probably is possible to download from http://partners.adobe.com/asn/developer/acrosdk/docs.html. Look especially at chapter 4 and 5, Graphics and Text, and the Operator summary.
Whenever the function prAdd() is used in this tutorial, you can probably get more explanations in the "PDF-reference manual". The code, you add to the content stream with prAdd(), has to follow the PDF syntax completely.
JavaScript:
You can add JavaScript to your PDF-file programmatically. This works with Acrobat Reader 5.0.5 or Acrobat 5.0 and higher versions.
You should have the "Acrobat JavaScript Object Specification" by hand. If you havent got Acrobat, you can probably download it from http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html. It is technical note # 5186. JavaScript for HTML and PDF differs so much that you need the manual, even if you know JavaScript very well.
11
Programming -> Libraries
0.049MB
GPL GNU General Public License
Show Detail
XML::Smart::Tutorial is a Perl module with tutorials and examples for XML::Smart.
SYNOPSIS
This document is a tutorial for XML::Smart and shows some examples of usual things.
SYNOPSIS
This document is a tutorial for XML::Smart and shows some examples of usual things.
12
Programming -> Libraries
0.52MB
Perl Artistic License
Show Detail
Jifty::Manual::Tutorial is a Perl module for Zero to Jifty in a Jiffy.
This tutorial should give you everything you need to build your first application with Jifty.
HOW TO
The requirements
Heres what you need to have installed -- at least when we write it.
Installing Jifty
No bones about it. We believe pretty strongly in the DRY (Dont Repeat Yourself) principle. Thats one of the big reasons we love Perl and CPAN. Jifty makes use of lots of amazing code from CPAN. At last count, it directly depended on 60 packages from CPAN. Most of these libraries are cross-platform pure-Perl packages and should run great out of the box on any platform you can get Perl onto.
Weve gone to lengths to make sure you dont spend your day downloading library after library by bundling everything we can inside the Jifty package. With luck, all youll need to install is a few tricky libraries that actually need to be compiled for your operating system. (Little things like Perls database interface and the embedded SQLite that Jifty defaults to.)
You can either grab a complete Jifty package from http://download.jifty.org/pub/jifty/ or install from CPAN. If you get the slim version from CPAN, youll have to install Jiftys dependencies yourself. (Though we help out with that where we can.) If you want to get up and running quickly, grab the latest version from:
http://download.jifty.org/pub/jifty/
Either way, the installation process is the same:
# tar xzvf jifty- .tgz
# cd jifty-
# perl Makefile.PL
# make
# make test
# make install
If the tests dont pass, we want to hear about it. Please join us on jifty-devel@lists.jifty.org and report the failure. (See "GETTING HELP" below for info on how to join the list.)
This tutorial should give you everything you need to build your first application with Jifty.
HOW TO
The requirements
Heres what you need to have installed -- at least when we write it.
Installing Jifty
No bones about it. We believe pretty strongly in the DRY (Dont Repeat Yourself) principle. Thats one of the big reasons we love Perl and CPAN. Jifty makes use of lots of amazing code from CPAN. At last count, it directly depended on 60 packages from CPAN. Most of these libraries are cross-platform pure-Perl packages and should run great out of the box on any platform you can get Perl onto.
Weve gone to lengths to make sure you dont spend your day downloading library after library by bundling everything we can inside the Jifty package. With luck, all youll need to install is a few tricky libraries that actually need to be compiled for your operating system. (Little things like Perls database interface and the embedded SQLite that Jifty defaults to.)
You can either grab a complete Jifty package from http://download.jifty.org/pub/jifty/ or install from CPAN. If you get the slim version from CPAN, youll have to install Jiftys dependencies yourself. (Though we help out with that where we can.) If you want to get up and running quickly, grab the latest version from:
http://download.jifty.org/pub/jifty/
Either way, the installation process is the same:
# tar xzvf jifty- .tgz
# cd jifty-
# perl Makefile.PL
# make
# make test
# make install
If the tests dont pass, we want to hear about it. Please join us on jifty-devel@lists.jifty.org and report the failure. (See "GETTING HELP" below for info on how to join the list.)
13
Programming -> Libraries
0.11MB
Perl Artistic License
Show Detail
XML::XQL::Tutorial is a Perl module that describes the XQL query syntax.
This document describes basic the features of the XML Query Language (XQL.) A proposal for the XML Query Language (XQL) specification was submitted to the XSL Working Group in September 1998. The spec can be found at http://www.w3.org/TandS/QL/QL98/pp/xql.html. Since it is only a proposal at this point, things may change, but it is very likely that the final version will be close to the proposal. Most of this document was copied straight from the spec.
See also the XML::XQL man page.
XQL (XML Query Language) provides a natural extension to the XSL pattern language. It builds upon the capabilities XSL provides for identifying classes of nodes, by adding Boolean logic, filters, indexing into collections of nodes, and more.
XQL is designed specifically for XML documents. It is a general purpose query language, providing a single syntax that can be used for queries, addressing, and patterns. XQL is concise, simple, and powerful.
XQL is designed to be used in many contexts. Although it is a superset of XSL patterns, it is also applicable to providing links to nodes, for searching repositories, and for many other applications.
Note that the term XQL is a working term for the language described in this proposal. It is not their intent that this term be used permanently. Also, beware that another query language exists called XML-QL, which uses a syntax very similar to SQL.
The XML::XQL module has added functionality to the XQL spec, called XQL+. To allow only XQL functionality as described in the spec, use the XML::XQL::Strict module. Note that the XQL spec makes the distinction between core XQL and XQL extensions. This implementation makes no distinction and the Strict module, therefore, implements everything described in the XQL spec. See the XML::XQL man page for more information about the Strict module. This tutorial will clearly indicate when referring to XQL+.
This document describes basic the features of the XML Query Language (XQL.) A proposal for the XML Query Language (XQL) specification was submitted to the XSL Working Group in September 1998. The spec can be found at http://www.w3.org/TandS/QL/QL98/pp/xql.html. Since it is only a proposal at this point, things may change, but it is very likely that the final version will be close to the proposal. Most of this document was copied straight from the spec.
See also the XML::XQL man page.
XQL (XML Query Language) provides a natural extension to the XSL pattern language. It builds upon the capabilities XSL provides for identifying classes of nodes, by adding Boolean logic, filters, indexing into collections of nodes, and more.
XQL is designed specifically for XML documents. It is a general purpose query language, providing a single syntax that can be used for queries, addressing, and patterns. XQL is concise, simple, and powerful.
XQL is designed to be used in many contexts. Although it is a superset of XSL patterns, it is also applicable to providing links to nodes, for searching repositories, and for many other applications.
Note that the term XQL is a working term for the language described in this proposal. It is not their intent that this term be used permanently. Also, beware that another query language exists called XML-QL, which uses a syntax very similar to SQL.
The XML::XQL module has added functionality to the XQL spec, called XQL+. To allow only XQL functionality as described in the spec, use the XML::XQL::Strict module. Note that the XQL spec makes the distinction between core XQL and XQL extensions. This implementation makes no distinction and the Strict module, therefore, implements everything described in the XQL spec. See the XML::XQL man page for more information about the Strict module. This tutorial will clearly indicate when referring to XQL+.
14
Programming -> Libraries
0.76MB
Perl Artistic License
Show Detail
Template::Tutorial::Datafile is a Perl module for creating Data Output Files Using the Template Toolkit.
This tutorial gives an overview of the Template Toolkit, showing in particular how to use it to read and write data files in various different formats and styles. It was written by Dave Cross and first appeared as a lead article at http://www.perl.com/ earlier in the year (2001).
Introducing the Template Toolkit
There are a number of Perl modules that are universally recognised as The Right Thing To Use for certain tasks. If you accessed a database without using DBI, pulled data from the WWW without using one of the LWP modules or parsed XML without using XML::Parser or one of its subclasses then youd run the risk of being shunned by polite Perl society.
I believe that the year 2000 saw the emergence of another must have Perl module - the Template Toolkit. I dont think Im alone in this belief as the Template Toolkit won the Best New Module award at the Perl Conference last summer. Version 2.0 of the Template Toolkit (known as TT2 to its friends) was recently released to the CPAN.
TT2 was designed and written by Andy Wardley. It was born out of Andys previous templating module, Text::Metatext, in best Fred Brooks plan to throw one away manner; and aims to be the most useful (or, at least, the most used) Perl templating system.
TT2 provides a way to take a file of fixed boilerplate text (the template) and embed variable data within it. One obvious use of this is in the creation of dynamic web pages and this is where a lot of the attention that TT2 has received has been focussed. In this article, I hope to demonstrate that TT2 is just as useful in non-web applications.
This tutorial gives an overview of the Template Toolkit, showing in particular how to use it to read and write data files in various different formats and styles. It was written by Dave Cross and first appeared as a lead article at http://www.perl.com/ earlier in the year (2001).
Introducing the Template Toolkit
There are a number of Perl modules that are universally recognised as The Right Thing To Use for certain tasks. If you accessed a database without using DBI, pulled data from the WWW without using one of the LWP modules or parsed XML without using XML::Parser or one of its subclasses then youd run the risk of being shunned by polite Perl society.
I believe that the year 2000 saw the emergence of another must have Perl module - the Template Toolkit. I dont think Im alone in this belief as the Template Toolkit won the Best New Module award at the Perl Conference last summer. Version 2.0 of the Template Toolkit (known as TT2 to its friends) was recently released to the CPAN.
TT2 was designed and written by Andy Wardley. It was born out of Andys previous templating module, Text::Metatext, in best Fred Brooks plan to throw one away manner; and aims to be the most useful (or, at least, the most used) Perl templating system.
TT2 provides a way to take a file of fixed boilerplate text (the template) and embed variable data within it. One obvious use of this is in the creation of dynamic web pages and this is where a lot of the attention that TT2 has received has been focussed. In this article, I hope to demonstrate that TT2 is just as useful in non-web applications.
15
Programming -> Libraries
0.91MB
Perl Artistic License
Show Detail
OpenInteract2::Manual::Tutorial is a Perl module that will teach learn you how to create and modify a package.
SYNOPSIS
This tutorial will show you the different methods for creating a package and how to maintain them.
CREATING THE PACKAGE
A word on the example
For our example were going to create a book package. This will keep track of all our books and allow us to search our library, add new books, update existing ones and remove old ones. It wont be the backbone for a massive e-commerce website to make you lots of money. It does not attempt to best model the relationships for all the data about a book.
Looking for shortcuts?
If you want to get something running in the fastest manner possible we can generate a simple CRUDS application for you. (CRUDS: CReate Update Delete Search) Just run something like the following:
$ oi2_manage easy_app --package=book --table=book
--dsn=DBI:Pg:dbname=mylibrary --username=foo --password=bar
This will create a simple application built off a table book with templates and objects for searching, creating, updating and removing objects. (More at OpenInteract2::Manage::Package::CreatePackageFromTable.)
Since this is a tutorial well assume you want to read to learn, so on we go.
Generating the skeleton
OpenInteract comes with tools to create a skeleton package -- we dont want to do all this from scratch! The skeleton package has the directory structure, metadata and a number of files to get you going on your new package. Heres how to create one -- be sure to first go to the directory under which the package will be created:
$ oi2_manage create_package --package=book
And heres what youll see:
PROGRESS: Starting task
PROGRESS: Task complete
ACTION: Create package book
OK: Package book created ok in /path/to/my/book
And now lets see what it created:
$ find book/
book/
book/conf
book/conf/spops.ini
book/conf/action.ini
book/data
book/doc
book/doc/book.pod
book/struct
book/template
book/template/sample.tmpl
book/script
book/html
book/html/images
book/OpenInteract2
book/OpenInteract2/Action
book/OpenInteract2/Action/Book.pm
book/OpenInteract2/SQLInstall
book/OpenInteract2/SQLInstall/Book.pm
book/package.ini
book/MANIFEST.SKIP
book/Changes
book/MANIFEST
These files and directories are explained in OpenInteract2::Manual::Packages.
You will normally need to edit/add the following:
book/package.ini # Add name, version, author information
book/MANIFEST # Add names of distribution files
book/conf/spops.ini # Describe the objects your package uses
book/conf/action.ini # Map URLs to handlers in your package
book/data # Specify the initial data and security
book/struct # Describe the tables used to store your objects
book/template # HTML to display and manipulate your objects
book/OpenInteract2 # Optional Perl modules defining object behavior
book/OpenInteract2/Action # Manipulate objects for desired functionality
book/OpenInteract2/SQLInstall # Tell the installer about your tables, data, security
book/doc/book.pod # Last but not least, tell the world about it
Short sidebar: Creating a MANIFEST
Notice that we create a MANIFEST file for you when the package is created. As you add more files to your package youll need to add them to your book/MANIFEST. Fortunately, it can be created automatically:
$ cd /path/to/mypackage
$ perl -MExtUtils::Manifest -e ExtUtils::Manifest::mkmanifest()
Thats it! If you have an old MANIFEST file in the directory it will be copied to MANIFEST.bak. Also note that files matching patterns in the book/MANIFEST.SKIP file will not be included.
SYNOPSIS
This tutorial will show you the different methods for creating a package and how to maintain them.
CREATING THE PACKAGE
A word on the example
For our example were going to create a book package. This will keep track of all our books and allow us to search our library, add new books, update existing ones and remove old ones. It wont be the backbone for a massive e-commerce website to make you lots of money. It does not attempt to best model the relationships for all the data about a book.
Looking for shortcuts?
If you want to get something running in the fastest manner possible we can generate a simple CRUDS application for you. (CRUDS: CReate Update Delete Search) Just run something like the following:
$ oi2_manage easy_app --package=book --table=book
--dsn=DBI:Pg:dbname=mylibrary --username=foo --password=bar
This will create a simple application built off a table book with templates and objects for searching, creating, updating and removing objects. (More at OpenInteract2::Manage::Package::CreatePackageFromTable.)
Since this is a tutorial well assume you want to read to learn, so on we go.
Generating the skeleton
OpenInteract comes with tools to create a skeleton package -- we dont want to do all this from scratch! The skeleton package has the directory structure, metadata and a number of files to get you going on your new package. Heres how to create one -- be sure to first go to the directory under which the package will be created:
$ oi2_manage create_package --package=book
And heres what youll see:
PROGRESS: Starting task
PROGRESS: Task complete
ACTION: Create package book
OK: Package book created ok in /path/to/my/book
And now lets see what it created:
$ find book/
book/
book/conf
book/conf/spops.ini
book/conf/action.ini
book/data
book/doc
book/doc/book.pod
book/struct
book/template
book/template/sample.tmpl
book/script
book/html
book/html/images
book/OpenInteract2
book/OpenInteract2/Action
book/OpenInteract2/Action/Book.pm
book/OpenInteract2/SQLInstall
book/OpenInteract2/SQLInstall/Book.pm
book/package.ini
book/MANIFEST.SKIP
book/Changes
book/MANIFEST
These files and directories are explained in OpenInteract2::Manual::Packages.
You will normally need to edit/add the following:
book/package.ini # Add name, version, author information
book/MANIFEST # Add names of distribution files
book/conf/spops.ini # Describe the objects your package uses
book/conf/action.ini # Map URLs to handlers in your package
book/data # Specify the initial data and security
book/struct # Describe the tables used to store your objects
book/template # HTML to display and manipulate your objects
book/OpenInteract2 # Optional Perl modules defining object behavior
book/OpenInteract2/Action # Manipulate objects for desired functionality
book/OpenInteract2/SQLInstall # Tell the installer about your tables, data, security
book/doc/book.pod # Last but not least, tell the world about it
Short sidebar: Creating a MANIFEST
Notice that we create a MANIFEST file for you when the package is created. As you add more files to your package youll need to add them to your book/MANIFEST. Fortunately, it can be created automatically:
$ cd /path/to/mypackage
$ perl -MExtUtils::Manifest -e ExtUtils::Manifest::mkmanifest()
Thats it! If you have an old MANIFEST file in the directory it will be copied to MANIFEST.bak. Also note that files matching patterns in the book/MANIFEST.SKIP file will not be included.
16
Programming -> Libraries
0.049MB
Perl Artistic License
Show Detail
Album::Tutorial is a Perl module on how to use the Album program.
SYNOPSIS
This tutorial describes the basic use of the Album program to create and maintain browser based photo albums.
Getting started
To get started, create a new directory and cd to it. Create a subdirectory large and put some pictures there. If you have installed the album tool in your execution path, you can now execute it as follows:
$ album -v
No info.dat, adding images from large
info.dat: Cannot update (does not exist)
Number of entries = 7 (7 added)
mkdir thumbnails
mkdir icons
mkdir css
Creating icons: first-gr.png first.png ... sound.png movie.jpg
Creating style sheets: common.css index.css ... journal.css
im023.jpg: thumbnail OK
im024.jpg: thumbnail OK
im025.jpg: thumbnail OK
im026.jpg: thumbnail OK
im027.jpg: thumbnail OK
im028.jpg: thumbnail OK
im029.jpg: thumbnail OK
Creating pages for 7 images
(Needed to write 7 image pages)
Creating pages for 1 index
(Needed to write 1 index page)
Your results will vary, but be similar to this example run. What you can see is that album found 7 images in the large directory, created thumbnails, icons and css directories, created thumbnails by resizing the images, and finally created the HTML pages. You can inspect your first photo album by opening file index.html with your favorite browser. You can click on any image to see the larger version. Navigation buttons are provided to the left of the image.
It is interesting to run album again:
$ album -v
No info.dat, adding images from large
info.dat: Cannot update (does not exist)
Number of entries = 7 (7 added)
.......[7]
Creating pages for 7 images
(No image pages needed updating)
Creating pages for 1 index
(No index pages needed updating)
album tries to avoid doing unnecessary work as much as possible. In this case, all thumbnails and image and index pages are up to date. The line of periods shows progress, one period for each image processed.
SYNOPSIS
This tutorial describes the basic use of the Album program to create and maintain browser based photo albums.
Getting started
To get started, create a new directory and cd to it. Create a subdirectory large and put some pictures there. If you have installed the album tool in your execution path, you can now execute it as follows:
$ album -v
No info.dat, adding images from large
info.dat: Cannot update (does not exist)
Number of entries = 7 (7 added)
mkdir thumbnails
mkdir icons
mkdir css
Creating icons: first-gr.png first.png ... sound.png movie.jpg
Creating style sheets: common.css index.css ... journal.css
im023.jpg: thumbnail OK
im024.jpg: thumbnail OK
im025.jpg: thumbnail OK
im026.jpg: thumbnail OK
im027.jpg: thumbnail OK
im028.jpg: thumbnail OK
im029.jpg: thumbnail OK
Creating pages for 7 images
(Needed to write 7 image pages)
Creating pages for 1 index
(Needed to write 1 index page)
Your results will vary, but be similar to this example run. What you can see is that album found 7 images in the large directory, created thumbnails, icons and css directories, created thumbnails by resizing the images, and finally created the HTML pages. You can inspect your first photo album by opening file index.html with your favorite browser. You can click on any image to see the larger version. Navigation buttons are provided to the left of the image.
It is interesting to run album again:
$ album -v
No info.dat, adding images from large
info.dat: Cannot update (does not exist)
Number of entries = 7 (7 added)
.......[7]
Creating pages for 7 images
(No image pages needed updating)
Creating pages for 1 index
(No index pages needed updating)
album tries to avoid doing unnecessary work as much as possible. In this case, all thumbnails and image and index pages are up to date. The line of periods shows progress, one period for each image processed.
17
Programming -> Libraries
0.073MB
Perl Artistic License
Show Detail
Task::Catalyst::Tutorial is a Perl module that installs everything you need to learn Catalyst.
SYNOPSIS
Installs the example "MyApp" described in Catalyst::Manual::Tutorial, and all its dependencies.
SYNOPSIS
Installs the example "MyApp" described in Catalyst::Manual::Tutorial, and all its dependencies.
18
Programming -> Libraries
0.28MB
Perl Artistic License
Show Detail
Bigtop::Docs::Tutorial is a simple case study of building a web app with bigtop.
Many (not all) applications are mostly data managers. That is, they are really intermediaries between users and various tables in a database. A bigtop file is meant to be a single place to describe all (or practically all) facits of the data in an application. This includes at least:
· The name and special features of each controller.
· The name of each table in the database.
· A description of each column (field) in each table in the database. This includes at least:
- its name and SQL type
- the label the user sees for it when it appears on the screen
- what type of html form element the user uses to enter or update it
- how the data is validated and filtered on its way into and out of the database (filtering yet supported)
- which table the field refers to if it is a foreign key
- etc.
All of these things, and more, are described in a Bigtop file. That file can be given to bigtop to build the application. Once it is built, it can be safely rebuilt so that only the generated bits are changed (this is accomplished by maintaining a clean separation between generated and hand edited files, and by config options in the bigtop file).
Notice that nothing in the above has committed you or me to any particular web application framework, data modeling scheme, templating system, or web server. Bigtop is neutral (think big tent), at least for Perl apps delivered via the web.
Many (not all) applications are mostly data managers. That is, they are really intermediaries between users and various tables in a database. A bigtop file is meant to be a single place to describe all (or practically all) facits of the data in an application. This includes at least:
· The name and special features of each controller.
· The name of each table in the database.
· A description of each column (field) in each table in the database. This includes at least:
- its name and SQL type
- the label the user sees for it when it appears on the screen
- what type of html form element the user uses to enter or update it
- how the data is validated and filtered on its way into and out of the database (filtering yet supported)
- which table the field refers to if it is a foreign key
- etc.
All of these things, and more, are described in a Bigtop file. That file can be given to bigtop to build the application. Once it is built, it can be safely rebuilt so that only the generated bits are changed (this is accomplished by maintaining a clean separation between generated and hand edited files, and by config options in the bigtop file).
Notice that nothing in the above has committed you or me to any particular web application framework, data modeling scheme, templating system, or web server. Bigtop is neutral (think big tent), at least for Perl apps delivered via the web.
19
Programming -> Libraries
0.030MB
Perl Artistic License
Show Detail
Chatbot::Alpha::Tutorial is a beginners guide to Chatbot::Alpha 2.x.
INTRODUCTION
What is Chatbot::Alpha?
Chatbot::Alpha is a Perl module for reading and processing Alpha code. Alpha code is a command-driven response language, primarily used for chatterbots.
The language format is quite simple: its a line-by-line language. The first character is the command, followed by the commands data. The simplest of all Alpha replies is the standard one-way question and answer:
+ hello bot
- Hello human.
Alpha Commands Overview
Here are all the commands supported by Chatbot::Alpha:
+ (Plus)
The + symbol is the basis of all your replies. Its the trigger--that is, what the user says to activate that reply. In most cases this command comes first in a reply, followed by supporting commands that tell the bot what to do next.
- (Minus)
The - command has many purposes. In the example above, a single +TRIGGER and a single -REPLY will give you a one-way question-answer case. If you use multiple -REPLYs under one +TRIGGER, then they will become random responses. On *CONDITIONS, the -REPLYs will be called when no condition returns true. On &HOLDERS, the -REPLY is the first thing the bot sends. And the list goes on... well get into the many uses for -REPLY later.
% (Percent)
The % command is for "that" emulation. If youve worked with AIML youll know what that refers to. Its there to help take the A.D.D. syndrome out of your bots. You can make specific replies based on what the bot last said. Like if the bot asks "Do you have any pets?" and the user says "yes", the bot can ask "What kind of pets?" instead of a generic reply to "yes". Youll learn all about this in the tutorial later.
^ (Carat)
The ^ command is to continue from your last -REPLY. For example, if your reply is very long and you want to break it down a few lines in the reply file (as not to have a horizontal scrollbar and be hard to read), this is the command to use. The ^CONTINUE command will adds its data to the last -REPLY you used under the +TRIGGER.
@ (At)
The @ command is for a redirection. Alpha triggers are "dead-on", meaning "hello|hey" is literally "hello|hey", not "hello OR hey". So when you want one to point to the other, use the @REDIRECT command.
* (Star)
The * is for conditionals. Youll learn about these later as well.
& (Amperstand)
This is for simple conversation holders. Emphasis is on the word "simple." They dont always work, so youd use %THAT if it was really important. The &HOLDER command is slowly becoming deprecated.
# (Pound)
The # command is for executing Perl codes within your reply set. Sometimes Alpha just cant handle the complex tasks you have in mind, and this can fill in all the blanks (assuming youre fluent with Perl anyway).
/ (Slash)
This is comment data, not processed within Chatbot::Alpha.
LessThan and GreaterThan
The > and <>
INTRODUCTION
What is Chatbot::Alpha?
Chatbot::Alpha is a Perl module for reading and processing Alpha code. Alpha code is a command-driven response language, primarily used for chatterbots.
The language format is quite simple: its a line-by-line language. The first character is the command, followed by the commands data. The simplest of all Alpha replies is the standard one-way question and answer:
+ hello bot
- Hello human.
Alpha Commands Overview
Here are all the commands supported by Chatbot::Alpha:
+ (Plus)
The + symbol is the basis of all your replies. Its the trigger--that is, what the user says to activate that reply. In most cases this command comes first in a reply, followed by supporting commands that tell the bot what to do next.
- (Minus)
The - command has many purposes. In the example above, a single +TRIGGER and a single -REPLY will give you a one-way question-answer case. If you use multiple -REPLYs under one +TRIGGER, then they will become random responses. On *CONDITIONS, the -REPLYs will be called when no condition returns true. On &HOLDERS, the -REPLY is the first thing the bot sends. And the list goes on... well get into the many uses for -REPLY later.
% (Percent)
The % command is for "that" emulation. If youve worked with AIML youll know what that refers to. Its there to help take the A.D.D. syndrome out of your bots. You can make specific replies based on what the bot last said. Like if the bot asks "Do you have any pets?" and the user says "yes", the bot can ask "What kind of pets?" instead of a generic reply to "yes". Youll learn all about this in the tutorial later.
^ (Carat)
The ^ command is to continue from your last -REPLY. For example, if your reply is very long and you want to break it down a few lines in the reply file (as not to have a horizontal scrollbar and be hard to read), this is the command to use. The ^CONTINUE command will adds its data to the last -REPLY you used under the +TRIGGER.
@ (At)
The @ command is for a redirection. Alpha triggers are "dead-on", meaning "hello|hey" is literally "hello|hey", not "hello OR hey". So when you want one to point to the other, use the @REDIRECT command.
* (Star)
The * is for conditionals. Youll learn about these later as well.
& (Amperstand)
This is for simple conversation holders. Emphasis is on the word "simple." They dont always work, so youd use %THAT if it was really important. The &HOLDER command is slowly becoming deprecated.
# (Pound)
The # command is for executing Perl codes within your reply set. Sometimes Alpha just cant handle the complex tasks you have in mind, and this can fill in all the blanks (assuming youre fluent with Perl anyway).
/ (Slash)
This is comment data, not processed within Chatbot::Alpha.
LessThan and GreaterThan
The > and <>
20
Programming -> Libraries
0.053MB
Perl Artistic License
Show Detail
Test::LectroTest::Tutorial is a Perl module that contains documentation on how to use LectroTest to test your software.
SYNOPSIS
LectroTest is an automated, specification-based testing system. To use it, declare properties that specify the expected behavior of your software. Then invoke LectroTest to test whether those properties hold.
LectroTest does this by running repeated random trials against your software. If LectroTest finds that a property doesnt hold, it emits the counterexample that "broke" your software. You can then plug the counterexample into your software to debug the problem. (Its also a good idea to add the counterexample to your list of regression tests.)
Think of your softwares behavior as a haystack that youre searching for needles. Each error is a needle. You want to find the needles and remove of them. LectroTest will search the haystack for you -- its nice that way -- but first you must tell it about the shape of the haystack and how to recognize a needle when it sees one.
The Haystack
The shape of the haystack is defined by a set of "generator bindings," in which variables are bound to the output of value generators:
x = 0;
The above asserts for each point in the haystack that the output of the function the_thing_we_are_testing must be non-negative.
Put them together to make a Property
The generator bindings and needle recognizer are combined to make a property:
Property {
##[ x = 0;
}, name => "the_thing_we_are_testing(...) is non-negative";
Youll note that we also added a meaningful name. Although not strictly required, its an excellent practice that makes life easier. (Youll also note that we placed the generator bindings inside of the magic delimiters ##[ ]##. This tells Perl that our bindings are bindings and not regular Perl code.)
We can read the above property like so: "For all integers x and all characters c in the range A through Z, we assert that the_thing_we_are_testing is non-negative."
Testing whether your Properties hold
After you define properties for your software, just add them to a small Perl program that uses the Test::LectroTest module:
# MyProperties.l.t
use MyModule; # provides the_thing_we_are_testing
use Test::LectroTest;
Property {
##[ x = 0;
}, name => "the_thing_we_are_testing(...) is non-negative";
Then you can test your properties simply by running the program:
$ perl MyProperties.l.t
If your properties check out, youll see something like this:
1..1
ok 1 - the_thing_we_are_testing(...) is non-negative (1000 attempts)
If something goes wrong, however, LectroTest will tell you where it happened:
1..1
not ok 1 - the_thing_we_are_testing(...) is non-negative
falsified in 23 attempts
# Counterexample:
# $x = 4
# $c = "R"
What this says is that at the point (x=4, c="R") in the haystack, there is a needle (i.e., your property doesnt hold). With this information, you can examine your code to determine the cause of the error.
SYNOPSIS
LectroTest is an automated, specification-based testing system. To use it, declare properties that specify the expected behavior of your software. Then invoke LectroTest to test whether those properties hold.
LectroTest does this by running repeated random trials against your software. If LectroTest finds that a property doesnt hold, it emits the counterexample that "broke" your software. You can then plug the counterexample into your software to debug the problem. (Its also a good idea to add the counterexample to your list of regression tests.)
Think of your softwares behavior as a haystack that youre searching for needles. Each error is a needle. You want to find the needles and remove of them. LectroTest will search the haystack for you -- its nice that way -- but first you must tell it about the shape of the haystack and how to recognize a needle when it sees one.
The Haystack
The shape of the haystack is defined by a set of "generator bindings," in which variables are bound to the output of value generators:
x = 0;
The above asserts for each point in the haystack that the output of the function the_thing_we_are_testing must be non-negative.
Put them together to make a Property
The generator bindings and needle recognizer are combined to make a property:
Property {
##[ x = 0;
}, name => "the_thing_we_are_testing(...) is non-negative";
Youll note that we also added a meaningful name. Although not strictly required, its an excellent practice that makes life easier. (Youll also note that we placed the generator bindings inside of the magic delimiters ##[ ]##. This tells Perl that our bindings are bindings and not regular Perl code.)
We can read the above property like so: "For all integers x and all characters c in the range A through Z, we assert that the_thing_we_are_testing is non-negative."
Testing whether your Properties hold
After you define properties for your software, just add them to a small Perl program that uses the Test::LectroTest module:
# MyProperties.l.t
use MyModule; # provides the_thing_we_are_testing
use Test::LectroTest;
Property {
##[ x = 0;
}, name => "the_thing_we_are_testing(...) is non-negative";
Then you can test your properties simply by running the program:
$ perl MyProperties.l.t
If your properties check out, youll see something like this:
1..1
ok 1 - the_thing_we_are_testing(...) is non-negative (1000 attempts)
If something goes wrong, however, LectroTest will tell you where it happened:
1..1
not ok 1 - the_thing_we_are_testing(...) is non-negative
falsified in 23 attempts
# Counterexample:
# $x = 4
# $c = "R"
What this says is that at the point (x=4, c="R") in the haystack, there is a needle (i.e., your property doesnt hold). With this information, you can examine your code to determine the cause of the error.
No comments:
Post a Comment