20
Ten modules I haven’t yet talked about I have modules on the CPAN and I haven’t yet given a talk about most of them. I’ll pick ten useful but less-known modules of mine and give two minute introductions to each. Léon Brocard London Perl Workshop

Ten modules I haven't yet talked about

  • Upload
    acme

  • View
    1.572

  • Download
    4

Embed Size (px)

DESCRIPTION

I have 77 modules on the CPAN and I haven't yet given a talk about most of them. I'll pick ten useful but less-known modules of mine and give two minute introductions to each

Citation preview

Page 1: Ten modules I haven't yet talked about

Ten modules I haven’t yet talkedabout

I have 77 modules on the CPAN and I haven’t yetgiven a talk about most of them. I’ll pick ten usefulbut less-known modules of mine and give two

minute introductions to each.Léon Brocard

London Perl Workshop 2008

Page 2: Ten modules I haven't yet talked about

Me

Léon BrocardFrench, live in LondonLike foodLike the colour orangeFounded Amsterdam.pm, Bath.pm, Croydon.pmNow in London.pmStarted YAPC::EuropePerl hacker

Page 3: Ten modules I haven't yet talked about

77 distributions on the CPAN

Acme-Buffy, Acme-Colour, App-Cache, Archive-Peek, Catalyst-Plugin-CookiedSession,Catalyst-Plugin-SimpleAuth, Compress-LZF_PP, Compress-LZMA-External, CPAN-IndexPod,CPAN-Metadata-RDF, CPAN-Mini-Webserver, CPAN-Unpack, Crypt-Skip32-Base32Crockford,Crypt-Skip32-Base64URLSafe, Data-Page, Data-UUID-Base64URLSafe, DateTime-Stringify,Devel-ebug, Devel-ebug-HTTP, Devel-Profit, Email-Send-Gandi, Email-Send-Gmail,File-Copy-Reliable, Fir, Games-GuessWord, Git-PurePerl, GraphViz, Haul,HTML-Fraction, HTML-TagCloud, HTTP-Server-Simple-Kwiki, Image-Imlib2,Image-Imlib2-Thumbnail, Image-Imlib2-Thumbnail-S3, Image-WorldMap,Java-JVM-Classfile, JSON-XS-VersionOneAndTwo, Kasago, Language-Functional, Mac-EyeTV,MealMaster, Messaging-Courier, Module-CPANTS-Generator, Module-Packaged, MP3-ID3Lib,Net-Amazon-S3, Net-Amazon-SimpleQueue, Net-DPAP-Client, Net-FTP-Throttle,Net-Mosso-CloudFiles, Net-OpenDHT, Net-Stomp, Net-VNC, Number-DataRate,OpenFrame-Segment-Apache, OpenFrame-Segment-Apache2, Parse-BACKPAN-Packages,Parse-CPAN-Authors, Parse-CPAN-Packages, Perl-Metric-Basic, PPIx-IndexOffsets,PPIx-LineToSub, Search-Mousse, String-Koremutake, Template-Plugin-Page,Template-Stash-Strict, Term-ProgressBar-Quiet, Test-Expect,Test-WWW-Mechanize-Catalyst, Tie-GHash, Tree-Ternary_XS, TV-Anytime, WWW-Gazetteer,WWW-Gazetteer-FallingRain, WWW-Gazetteer-Getty, WWW-Mechanize-Timed,WWW-Search-Google

Page 4: Ten modules I haven't yet talked about

Let’s pick ten

App-Cache, Data-UUID-Base64URLSafeCrypt::Skip32::Base32Crockford,Email-Send-Gmail, Games-GuessWord,HTML-Fraction,Image-Imlib2-Thumbnail,Image-WorldMap, Net-FTP-Throttle,String-Koremutake,Term-ProgressBar-QuietTerm-ProgressBar-Simple.

Page 5: Ten modules I haven't yet talked about

App-CacheEasy application-level caching

# in your class, stores in something like# ~/.parse_backpan_packages/cache/my $cache = App::Cache->new({ ttl => 60*60 });$cache->delete(’test’);my $data = $cache->get(’test’);my $code = $cache->get_code("code",

sub { $self->calculate() });my $html = $cache->get_url(

"http://www.google.com/");$cache->set(’test’, ’one’);$cache->set(’test’, { foo => ’bar’ });my $scratch = $cache->scratch;$cache->clear;

Page 6: Ten modules I haven't yet talked about

App-Cache

# in CPAN::Mini::Webservermy $cache = App::Cache->new({ ttl => 60 * 60 }

);my $parse_cpan_authors = $cache->get_code(

’parse_cpan_authors’,sub {

Parse::CPAN::Authors->new($authors_filename->stringify

)}

);

Page 7: Ten modules I haven't yet talked about

Crypt::Skip32::Base32Crockford

Crypt::Skip32 + Encode::Base32::Crockford =database record IDs in URLs

my $key = pack( ’H20’, "112233445566778899AA" );my $cipher = Crypt::Skip32::Base32Crockford->new($key);my $n = 3493209676;my $b32 = $cipher->encrypt_number_b32_crockford($n);# 1PT4W80my $m = $cipher->decrypt_number_b32_crockford($b32);# 3493209676

Page 8: Ten modules I haven't yet talked about

Email-Send-Gmail

Send Messages using Gmail

use Email::Send;use Email::Send::Gmail;use Email::Simple::Creator;

my $email = Email::Simple->create(header => [

From => ’[email protected]’,To => ’[email protected]’,Subject => ’Server down’,

],body => ’The server is down, panic!’,

);

Page 9: Ten modules I haven't yet talked about

Email-Send-Gmail

my $sender = Email::Send->new({

mailer => ’Gmail’,mailer_args => [

username => ’[email protected]’,password => ’XXXISABADPASSWORD’,

]}

);eval { $sender->send($email) };die "Error sending email: $@" if $@;

Page 10: Ten modules I haven't yet talked about

Games-GuessWordGuess the letters in a word (i. e. Hangman)

my $g = Games::GuessWord->new(file => "/path/to/wordlist"

);print "Score: " . $g->score . "\n";print "Chances: " . $g->chances . "\n";print "Answer: " . $g->answer . "\n";my @guesses = $g->guesses;$g->guess("t");# ...if ($g->won) {

print "You won!\n";$g->new_word;

}

Page 11: Ten modules I haven't yet talked about

HTML-Fraction

Encode fractions as HTML entities

my $fraction = HTML::Fraction->new;print $fraction->tweak($html);# 1/5 is ⅕

which is displayed as 1⁄5

Page 12: Ten modules I haven't yet talked about

Image-Imlib2-�umbnail

Generate a set of thumbnails of an image

my $t = Image::Imlib2::Thumbnail->new();foreach my $thumbnail

($t->generate( $image, $directory )) {my $name = $thumbnail->{name};my $width= $thumbnail->{width};my $height = $thumbnail->{height};my $type = $thumbnail->{type};my $filename = $thumbnail->{filename};print "$name/$type is $width x $height";print " at $filename\n";

}

Page 13: Ten modules I haven't yet talked about

Image-Imlib2-�umbnail

By default it generates thumbnails of the samedimension that Flickr generates:

Type Name Width HeightLandscape Square 75 75Landscape Thumbnail 100 75Landscape Small 240 180Landscape Medium 500 375Landscape Large 1024 768Portrait Square 75 75Portrait Thumbnail 75 100Portrait Small 180 240Portrait Medium 375 500Portrait Large 768 1024

Page 14: Ten modules I haven't yet talked about

Image-WorldMap

Create graphical world maps of data

use Image::WorldMap;my $map = Image::WorldMap->new("earth-small.png", "maian/8"

);$map->add(4.91, 52.35, "Amsterdam.pm");$map->add(-2.355399, 51.3828, "Bath.pm");$map->add(-0.093999, 51.3627, "Croydon.pm");$map->draw("test.png");

Page 15: Ten modules I haven't yet talked about

Image-WorldMap

CPANMirrors

Page 16: Ten modules I haven't yet talked about

Net-FTP-�rottle

�rottle FTP connections

my $ftp = Net::FTP::Throttle->new("ftp.example.com",MegabitsPerSecond => 2

)or die "Cannot connect: $@";

# then as with Net::FTP

Page 17: Ten modules I haven't yet talked about

String-Koremutake

Convert to/from Koremutake Memorable RandomStrings

use String::Koremutake;my $k = String::Koremutake->new;

my $s = $k->integer_to_koremutake(65535);# botretremy $i = $k->koremutake_to_integer(’koremutake’);# 10610353957

Page 18: Ten modules I haven't yet talked about

Term-ProgressBar-Simple

Edmund extended my Term-ProgressBar-Quiet:provides a simple progress meter if run interactively

use Term::ProgressBar::Simple;my @todo = ( (’x’) x 10 );my $progress = Term::ProgressBar::Quiet->new(

scalar(@todo),);

foreach my $todo (@todo) {# do something with $todo$progress++;

}$progress->message(’All done’);

Page 19: Ten modules I haven't yet talked about

Term-ProgressBar-Quiet

progress: 10% [=== ]0m06s Leftprogress: 40% [========== ]0m04s LeftAll doneprogress: 100% [==================]D 0h00m10s

Page 20: Ten modules I haven't yet talked about

�anks

Any questions?