Various cool stuff
Config Files
Hack Day Perl
Where to go now
Can you just add...?
Users are never satisfied
Always want something changed
Most users won't edit code
Most users can be trained to edit config files
Move as much as possible into config files
This is bad
#!/usr/bin/perl
use strict; use warnings;
## Configuration
my $debug = 0; my $email = 'dave@dave.org.uk'; my $output_file = 'output.txt';
## DO NOT EDIT BEYOND THIS POINT
Don't trust 'em
Something will get broken
Code doesn't match what is in source code control
Recipe for disaster
Don't do it
[debugging] debug=1 verbose=0
Most users will understand this
Provide them with a dry-run option
Tell them what would happen
Parse with Config::IniFiles
<debugging>
<debug>1</debug>
<verbose>0</debug>
</debugging>
or
<debugging
debug="1"
verbose="0" />
Too complicated
Parse with XML::Simple (or XML::LibXML / XML::XPath)
---
debugging:
debug: 1
verbose: 0
Looks a bit like INI file
Human-readable
Still give them a dry-run option
Parse with YAML
Config::Auto
"Magical config file parser"
Guesses where your config file is
Guesses what format it is in
And usually gets it right
Environment variables
Command line options
Parse with Getopt::Long
Need to establish an order of precedence
$debug = defined $opt{debug} ? $opt{debug} :
defined $ENV{DEBUG} ? $ENV{DEBUG} :
defined $conf{debug} ? $conf{debug} :
0;
BBC Backstage / Yahoo! Hack Day
June 16th 2007
Alexandra Palace
Mashups
Data Feeds / APIs
Web 2.0
CPAN modules can help
A lot of data available as web feeds
RSS / Atom
But which version of RSS
RDF vs RSS
XML::RSS
use XML::RSS;
my $rss = XML::RSS->new;
$rss->parsefile('myfeed.rss');
foreach (@{$rss->{items}}) {
print $_->{title}, "\n";
print $_->{link}, "n";
}
Supports RSS 0.9, 0.91, 1.0 and 2.0
Most of the versions you'll see in the wild
XML::Atom
use XML::Atom::Feed;
my $atom = XML::Atom::Feed->new('myatom.xml');
foreach ($atom->entries) {
print $_->title, "\n";
print $_->link, "\n";
}
Cleverer than XML::RSS
Handles things like autodiscovery
my @feeds =
XML::Atom::Feed->find_feeds('http://example.com/');
Not all XML feeds are valid XML
This is bad!
You should complain bitterly to the provider
But until it is fixed you can use XML::Liberal
Slightly badly named
What it parses isn't XML
Plagger - Pluggable RSS/Atom Aggregator
Huge distribution, installs half of CPAN
Dozens of small plugins
Single program (plagger)
YAML configuration file
Plagger::Plugin::Publish::Planet
plugins:
- module: Subscription::Config
config:
feed:
- url: http://api.flickr.com/services/feeds/photos_public.gne?tags=perlteachin
- url: http://technorati.com/watchlists/rss.html?wid=551975
- url: http://blogsearch.google.com/blogsearch_feeds?q=perl+teach-in&ie=utf-8&num=10&output=atom
...
- module: Publish::Planet
rule:
expression: $args->{feed}->id eq 'smartfeed:all'
config:
dir: /path/to/htdocs
theme: sixapart-std
Many web sites expose web services
REST, RPC, SOAP
HTTP request
Parse response
Usually XML
Many CPAN modules for handling web services
Wrappers around LWP or WWW::Mechanize
Parse response into data structures or objects
Make dealing with web services very easy
Net::Backpack
Net::Amazon::*
Flickr::API
Geo::Google
Geo::Coder::Yahoo
Many of these sites will monitor the requests you make
Use an API key
Apply for the key on the web site
Use the key in every request you use
Get details of photos
Details at http://www.flickr.com/services/api/
Many methods
Perl module gives low level access
Need to know the API pretty well
#!/usr/bin/perl
use strict; use warnings; use Flickr::API;
my $flickr = Flickr::API->new({
key => 'your key goes here'
});
my $response = $flickr->execute_method(
'flickr.photos.getRecent', { per_page => 2 }
);
print $response->content;
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="500" perpage="2" total="1000">
<photo id="525440809" owner="65666164@N00"
secret="3ab099b893" server="223" farm="1"
title="00760052" ispublic="1" isfriend="0"
isfamily="0" />
<photo id="525440801" owner="47391132@N00"
secret="d24451edc8" server="1009" farm="2"
title="041070 14 29B" ispublic="1" isfriend="0"
isfamily="0" />
</photos>
</rsp>
You might find an API that doesn't have a CPAN module
Easy to do it yourself
Read the API documentation
LWP / WWW::Mechanize
Parse the response
(Release to CPAN)
You don't need to be using Ruby on Rails to use AJAX
AJAX is largely just Javascript
With a server-side application
Which can be written in Perl
CGI::Ajax
Creates AJAX code in your CGI program output
Similar to Ruby on Rails AJAX helpers
JSON
Perl module for creating JSON
Common format for AJAX data exchange
Serialised Javascript Objects
A lot like YAML
Some suggestions for places to go for further information
Web sites
Books
Magazines
Mailing lists
Conferences
One of the largest Perl Monger groups
Mailing lists
Monthly social meetings
Occasional technical meetings
Annual London Perl Workshop
use Perl;
Perl news site
Also journals
perl.com
O'Reilly run site
High quality articles
Perl Monks
Best web site for Perl questions
Many Perl experts
The Perl directory
Lists of many Perl-related sites
Some recent Perl books
Perl Best Practices - Damian Conway
Advanced Perl Programming - Simon Cozens
Perl Hacks - chromatic, Conway & Poe
Intermediate Perl - Schwartz, foy & Phoenix
Mastering Perl - brian d foy
Higher Order Perl - Mark-Jason Dominus
Minimal Perl - Tim Maher
Pro Perl Debugging - Richard Foley & Joe McMahon
Perl & LWP - Sean M Burke
Updated online edition
The Perl Review
Randal's monthly columns
Linux Magazine
SysAdmin
Many mailing lists devoted to Perl topics
The Open Source Convention
Portland 23-27 July 2007
YAPC
Houston 25-25 June 2007
Vienna 28-30 August 2007
Brasil, Asia, Israel, Australia
One-Day Perl Workshops
That's all folks
Hope it was useful
Please fill in the evaluation forms
See you at London.pm
Which pub are we going to?