(originally presented at YAPC::Europe::2007)
No-one is as critical about something as those that love it dearly. Mark Fowler has been collecting complaints from professional Perl developers for years about what warts still remain with the language when strict and warnings are turned on.
Are these problems unsolvable? A veteran Perl programmer himself Mark attempted to try and solve these issues - and then turned to the experts, the people who write books on Perl, the people who maintain the perl interpreter itself, for help.
This is what he learned...
2. What this talk is not
ā¢ āWah, no one uses āuse strictāā
ā¢ āPeopleās perception of Perl is wrongā
ā¢ āThe CPAN/mailing list/a other website
isnāt exactly how I like itā
ā¢ āThe garbage collection de-allocation
routine isnāt very efļ¬centā
3. What this talk is
ā¢ Whatās a few major annoyances with Perl
ā¢ What we the humble programmer can do to
work around them
13. #!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use Template;
use DBD::SQLite;
use CGI;
use Parse::RecDescent;
use List::MoreUtils;
use Moose;
print quot;Hello Worldnquot;;
14. Make an executable
ā¢ perl -MCPAN -e āinstall PAR::Packerā
ā¢ pp -o hellow hellow.pl
ā¢ ...copy āhellowā to new computer
ā¢ ./hellow
Hello World
32. B
E
TA
Get Bleed Perl
ā¢ lwp-request $CPAN_URL >
perl-5.9.5.tar.gz
ā¢ gunzip -c perl-5.9.5.tar.gz | tar -xvf -
ā¢ cd perl-5.9.5
33. B
E
TA
Tell it where to go
ā¢ mkdir -p /User/mark/bin/perl5.9.5
ā¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/
mark/bin/perl5.9.5 -Duserelocatableinc -d
34. B
E
TA
Tell it where to go
ā¢ mkdir -p /User/mark/bin/perl5.9.5
ā¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/
mark/bin/perl5.9.5 -Duserelocatableinc -d
35. B
E
TA
Install it
ā¢ make
ā¢ make test
ā¢ make install
115. A
LP
H
A
Weāve already seen
source ļ¬lters
116. B
E
TA
PPI
ā¢ Pure Perl parser
ā¢ Only parses a subset of Perl
ā¢ Canāt tell the difference between certain
Perl constructs
ā¢ This said - very very good at what it does
122. B::Generate
ā¢ Can be used to create OP codes (i.e.
compiled Perl code) directly from Perl
123. use B::Generate;
# Do nothing, slowly.
CHECK {
my $null = new B::OP(quot;nullquot;,0);
my $enter = new B::OP(quot;enterquot;,0);
my $cop = new B::COP(0, quot;hiyaquot;, 0);
my $leave = new B::LISTOP(quot;leavequot;, 0, $enter, $null);
$leave->children(3);
$enter->sibling($cop);
$enter->next($cop);
$cop->sibling($null);
$null->next($leave);
$cop->next($leave);
# Tell Perl where to ļ¬nd our tree.
B::main_root($leave);
B::main_start($enter);
}
124. optomize.pm
ā¢ Can be used to manipulate the OP codes
after theyāve loaded
ā¢ Kinda like source ļ¬lters for compiled
bypecode
125. Use?
ā¢ PPI is reliable, but limited in itās ability
ā¢ Easy to try to do too much with
ā¢ Other techniques are very unstable / new
ā¢ B::Generate
ā¢ optomize
ā¢ MAD
126.
127. A
LP
H
A
package main;
use typesafety; # 'summary', 'debug';
my FooBar $foo; # establish type-checked variables
my FooBar $bar; # FooBar is the base class of references $bar will hold
my BazQux $baz;
$foo = new FooBar; # this is okay, because $foo holds FooBars
$bar = $foo; # this is okay, because $bar also holds FooBars
# $foo = 10; # this would throw an error - 10 is not a FooBar
# $baz = $foo; # not allowed - FooBar isn't a BazQux
$foo = $baz; # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also
typesafety::check(); # perform type check static analysis
128. A
LP
H
A
package main;
use typesafety; # 'summary', 'debug';
my FooBar $foo; # establish type-checked variables
my FooBar $bar; # FooBar is the base class of references $bar will hold
my BazQux $baz;
$foo = new FooBar; # this is okay, because $foo holds FooBars
$bar = $foo; # this is okay, because $bar also holds FooBars
# $foo = 10; # this would throw an error - 10 is not a FooBar
# $baz = $foo; # not allowed - FooBar isn't a BazQux
$foo = $baz; # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also
typesafety::check(); # perform type check static analysis
129. A
LP
H
A
package main;
use typesafety; # 'summary', 'debug';
my FooBar $foo; # establish type-checked variables
my FooBar $bar; # FooBar is the base class of references $bar will hold
my BazQux $baz;
$foo = new FooBar; # this is okay, because $foo holds FooBars
$bar = $foo; # this is okay, because $bar also holds FooBars
# $foo = 10; # this would throw an error - 10 is not a FooBar
# $baz = $foo; # not allowed - FooBar isn't a BazQux
$foo = $baz; # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also
typesafety::check(); # perform type check static analysis
130. A
LP
H
A
package main;
use typesafety; # 'summary', 'debug';
my FooBar $foo; # establish type-checked variables
my FooBar $bar; # FooBar is the base class of references $bar will hold
my BazQux $baz;
$foo = new FooBar; # this is okay, because $foo holds FooBars
$bar = $foo; # this is okay, because $bar also holds FooBars
# $foo = 10; # this would throw an error - 10 is not a FooBar
# $baz = $foo; # not allowed - FooBar isn't a BazQux
$foo = $baz; # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also
typesafety::check(); # perform type check static analysis