Advanced level training for Perl programmers
Turn intermediate programmers into advanced programmers
Attempt to fill some of the many current Perl vacancies in London
Perl is not dying
There are currently more Perl jobs than Perl programmers in London
London.pm jobs mailing list
Perl community jobs board
One of the largest Perl employers in London
BBC Backstage
backstage.bbc.co.uk is the BBC's developer network to encourage innovation and support new talent.
Various feeds and APIs
Lots of lovely data to mashup
Free stuff
BBC Backstage and Yahoo!
Hack Day 2007
Alexandra Palace
16/17th June
One day isn't enough time
We'll be moving fairly fast
Lots of pointers to other information
Feel free to ask questions
Use the mailing list
10:00 Session 1
CPAN
Templating
11:15 Coffee break
11:30 Session 2
ORM
Testing
Benchmarking
12:30 Lunch
13:30 Session 3
Object Oriented Perl
14:45 Coffee Break
15:00 Session 4
Various cool stuff
16:00 End (Pub?)
CPAN
Templating
Not going to introduce CPAN to you
Additional CPAN services
CPANTS
CPAN Projects
All modules uploaded to CPAN are automatically smoke tested
Downloaded, build and tested by over 400 testers
Multiple platforms
See the results at http://cpantesters.perl.org/
CPAN Testing Service
Tests modules for "Kwalitee"
It looks like quality
It sounds like quality
But it's not quite quality
Number of automatically measurable criteria to rate CPAN modules
has_readme, has_manifest, has_metayml, has_buildtool
has_tests
has_version, has_proper_version
no_pod_errors
has_test_pod, has_test_pod_coverage
use_strict
is_prereq
No kwalitee criterion is a quarantee of quality
The just tend to be seen in the same place as quality
It's possible to "game" the system
Produce modules that are written to raise kwalitee
Acme::Raise_my_kwalitee
Ensure kwalitee is high before releasing module
Test::Kwalitee
CPAN has very low entry requirements
Not very hard to get a CPAN login
This is generally a good thing
Many modules doing the same thing
All of them subtly different
None of them doing exactly what you want
Dozens of date/time modules on CPAN
Date::Manip is almost never what you want
Date::Calc, Date::Parse
Class::Date
Time::Piece
Date::Simple
What do you choose?
"The DateTime family of modules present a unified way to handle dates and times in Perl"
"... there are several different packages with overlapping functionality, but it was hard to take dates in one package and convert them to another which you would often have to do to get a function from a different package."
"unified" is good
Dozens of modules that work together in a consistant fashion
Simple case
#!/usr/bin/perl
use DateTime;
my $dt = DateTime->now; print $dt; # 2007-05-26T16:06:07 print $dt->dmy, "\n"; # 2007-05-26 print $dt->hms, "\n"; # 16:06:07
More advanced constructor
#!/usr/bin/perl
use DateTime;
my $dt = DateTime->new(year => 2007,
month => 6,
day => 2);
print $dt->ymd('/'), "\n"; # 2007/06/02
print $dt->month, "\n"; # 6
print $dt->month_name, "\n"; # June
A DateTime object is a point in time
For date arithmatic you need a duration
#!/usr/bin/perl
use DateTime;
my $dt = DateTime->new(year => 2007, month => 6,
day => 2);
my $two_weeks = DateTime::Duration->new(weeks => 2);
$dt += $two_weeks;
print $dt, "\n"; # 2007-06-16T00:00:00
Output formats with strftime
#!/usr/bin/perl
use DateTime;
my $dt = DateTime->new(year => 2007, month => 6,
day => 2);
print $dt->strftime('%A, %d %B %Y'), "\n";
# Saturday, 02 June 2007
Input format with DateTime::Format::Strptime
DateTime::Format::HTTP
DateTime::Format::MySQL
DateTime::Format::Excel
DateTime::Format::Baby (the big hand is on...)
DateTime::Calendar::Julian
DateTime::Calendar::Hebrew
DateTime::Calendar::Mayan
DateTime::Fiction::JRRTolkien::Shire
Similar problem as with dates
Dozens of overlapping modules
Don't interact well
The Perl Email Project (PEP) is a community dedicated to making Perl the best choice language for email processing. It maintains existing code, documents known problems and solutions, and develops new tools.
Most people use templates to produce web pages
Advantages are well known
Standard look and feel (static/dynamic)
Reusable components
Separation of code logic from display logic
Different skill-sets (HTML vs Perl)
The same advantages apply to non-web areas
Reports
Business documents
Configuration files
Anywhere you produce output
Must be easy - so many people do it
See perlfaq4
How can I expand variables in text strings?
$text = 'this has a $foo in it and a $bar';
%user_defs = (
foo => 23,
bar => 19,
);
$text =~ s/\$(\w+)/$user_defs{$1}/g;
Don't do that
Dozens of template modules on CPAN
Text::Template, HTML::Template, Mason, Template Toolkit
Many, many more
Questions to consider
HTML only?
Template language
I choose the Template Toolkit
Very powerful
Both web and non-web
Simple template language
Plugins give access to much of CPAN
Can use Perl code if you want
But don't do that
Data + Template = Output
Data + Alternative Template = Alternative Output
Different views of the same data
Only the template changes
#!/usr/bin/perl
use Template; use My::Object;
my ($id, $format) = @ARGV; $format ||= 'html';
my $obj = My::Object->new($id) or die; my $tt = Template->new;
$tt->process("$format.tt", { obj => $obj },
"$id.$format")
or die $tt->error;
No new code required
Just add new output template
Perl programmer need not be involved
Data + Template = Output
Template Toolkit
Template + Output = Data
Template::Extract
Data + Output = Template
Template::Generate
Back in 15 minutes