(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 efficent”
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
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 find 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 filters 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