SlideShare uma empresa Scribd logo
1 de 26
My Perl 
Bag of Tricks 
brian d foy 
The Perl Review 
Baltimore Perl mongers
•Eliminate special cases 
•Remove distractions 
•Know less 
•Let Perl do the work 
•Scale gracefully
% perl -e "print qq(Hello Worldn)" 
! 
% perl -le "print q(Hello World)"
my $string = some_sub(); 
! 
open my $fh, '<', $string; 
! 
while(<$fh>){ 
chomp; 
...; 
}
use 5.014; 
! 
my $new = $old =~ s/.../.../r; 
! 
foo( $old =~ s/.../.../r ); 
! 
print "%s %sn", 
$old, 
$old =~ s/.../.../r 
;
foreach my $file ( @files ) { 
open my($fh), '>', $file or do { 
warn "... $!n"; 
next FILE; 
}; 
... 
}
my $data = do { 
local $/; <DATA> 
}; 
...; 
! 
__END__ 
<?xml version="1.0"?> 
<root> 
... 
</root>
my $data = do { local $/; <DATA> }; 
! 
s|.*(?=<elem>)||; s|(?<=</elem>).*||; 
! 
my $name = 
m|<elem>(.*?)</elem>|; 
! 
__END__ 
<?xml version="1.0"?> 
<root> 
...<elem>Buster</elem> 
</root>
$g = 
q("Mimi","Bean,Buster","Roscoe"); 
! 
my @gatos = split /(?<="),(?=")/, $g;
$g = 
q("Roscoe "","" Cat","Bean, Buster"); 
! 
my @gatos = 
split 
/(?<!"")(?<="),(?=")(?!"")/, $g;
if( ref $r eq 'ARRAY' ) 
! 
if( ref $r eq ref [] ) 
! 
if( ref $r eq ref {} ) 
! 
if( ref $r eq ref sub {} ) 
! 
if( ref $r eq ref qr// )
join "n", @entries, ''; 
! 
join "nt", "t", @entries;
BEGIN { 
use Foo; 
package Foo; 
no warnings qw(redefine); 
sub foo { ... } 
}
# Git::CPAN::Patch 
! 
% git cpan-init http://... 
... hack hack hack ... 
% git commit 
% git cpan-sendpatch
my $file = MPEG::Info->new( ... ); 
! 
print 
join $/, 
map { 
$file->$_() 
} qw(acodec 
acodecraw 
achans 
... 
);
package Modulino { 
run(@ARGV) unless caller; 
! 
sub run { 
my @args = @_; 
...; 
} 
! 
}
if( /p{IsUppercaseRoman}/ ) { 
...} 
! 
# Ⅰ Ⅴ Ⅹ Ⅼ Ⅽ Ⅾ Ⅿ ↁ ↂ ↇ ↈ 
sub IsUppercaseRoman { 
return <<"CODE_NUMBERS"; 
2160 
2164 
2169 
216C 216F 
2181 2182 
2187 2188 
CODE_NUMBERS 
}
printf 
'%1$#b %1$#o %1$d %1$#xn", 
137; 
! 
! 
# 0b10001001 0211 137 0x89
gato( name => 'Buster' ); 
! 
sub gato { 
my %defaults = (...); 
my %config = (%defaults, @_ ); 
...; 
}
BEGIN { 
my $fixed_time = 1234567890; 
no warnings qw(redefine); 
! 
*CORE::GLOBAL::time = 
sub { $fixed_time }; 
! 
sub set_time { 
$fixed_time = $_[0] 
} 
} 
! 
ok( time > $fixed_time );
sub my_grep (&@) { 
my( $sub ) = shift; 
foreach my $arg ( @_ ) { 
local $_ = $arg; 
push @output, $arg 
if $sub->() 
} 
}
my $ucfirst_and_trim = 
composer( 
&trim_front, 
&trim_back, 
&my_ucfirst 
); 
! 
$s = $ucfirst_and_trim->($s);
sub composer { 
my (@sub_refs) = @_; 
sub { 
my $string = shift; 
foreach my $sub_ref (@sub_refs) { 
$string = $sub_ref->($string); 
} 
return $string; 
}; 
}
my @tests = ( 
# ARG EXPECTED LABEL 
[ [1,2,3], 6, 'Sum is 6' ], 
[ [-1,0,9], 8, 'Sum is 8' ], 
... 
); 
! 
foreach my $test ( @tests ) { 
is( 
target_sub( $test->[ARG] ), 
$test->[EXPECTED], 
$test->[LABEL] 
); 
}
package Local::Null::Logger { 
sub new { bless  my $x, $_[0] } 
sub AUTOLOAD { shift; print @_, $/ } 
sub DESTROY { 1 } 
} 
! 
sub _init_logger { 
my $log4perl_loaded = 
eval "require Log::Log4perl; 1"; 
unless( $log4perl_loaded ){ 
return Local::Null::Logger->new; 
} 
...; 
}
$object->foo->bar->baz->quux; 
! 
package Class { 
sub bar { 
return Null->new if $error; 
} 
} 
! 
package Null { 
my $null = bless {}, __PACKAGE__; 
sub new { $null } 
sub AUTOLOAD { return $_[0] } 
sub DESTROY { 1 } 
}

Mais conteúdo relacionado

Mais procurados

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Mais procurados (20)

Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Perl5i
Perl5iPerl5i
Perl5i
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6
 
7. Lower upper in Laravel
7. Lower upper in Laravel7. Lower upper in Laravel
7. Lower upper in Laravel
 
Dades i operadors
Dades i operadorsDades i operadors
Dades i operadors
 

Destaque

The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
brian d foy
 

Destaque (12)

I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
Tour of the Perl docs
Tour of the Perl docsTour of the Perl docs
Tour of the Perl docs
 
Create and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANCreate and upload your first Perl module to CPAN
Create and upload your first Perl module to CPAN
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transform
 
The Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyThe Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David Smiley
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPAN
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPAN
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginners
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
Improving the Solr Update Chain
Improving the Solr Update ChainImproving the Solr Update Chain
Improving the Solr Update Chain
 

Semelhante a Perl Bag of Tricks - Baltimore Perl mongers

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs
 

Semelhante a Perl Bag of Tricks - Baltimore Perl mongers (20)

Modern Perl
Modern PerlModern Perl
Modern Perl
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
wget.pl
wget.plwget.pl
wget.pl
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Tgh.pl
Tgh.plTgh.pl
Tgh.pl
 
Ae internals
Ae internalsAe internals
Ae internals
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

Mais de brian d foy (11)

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentation
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perl
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
Backward to DPAN
Backward to DPANBackward to DPAN
Backward to DPAN
 
Perl docs {sux|rulez}
Perl docs {sux|rulez}Perl docs {sux|rulez}
Perl docs {sux|rulez}
 
Why I Love CPAN
Why I Love CPANWhy I Love CPAN
Why I Love CPAN
 
What's wrong with the perldocs
What's wrong with the perldocsWhat's wrong with the perldocs
What's wrong with the perldocs
 
Frozen Perl 2011 Keynote
Frozen Perl 2011 KeynoteFrozen Perl 2011 Keynote
Frozen Perl 2011 Keynote
 
brian d foy
brian d foybrian d foy
brian d foy
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Perl Bag of Tricks - Baltimore Perl mongers

  • 1. My Perl Bag of Tricks brian d foy The Perl Review Baltimore Perl mongers
  • 2. •Eliminate special cases •Remove distractions •Know less •Let Perl do the work •Scale gracefully
  • 3. % perl -e "print qq(Hello Worldn)" ! % perl -le "print q(Hello World)"
  • 4. my $string = some_sub(); ! open my $fh, '<', $string; ! while(<$fh>){ chomp; ...; }
  • 5. use 5.014; ! my $new = $old =~ s/.../.../r; ! foo( $old =~ s/.../.../r ); ! print "%s %sn", $old, $old =~ s/.../.../r ;
  • 6. foreach my $file ( @files ) { open my($fh), '>', $file or do { warn "... $!n"; next FILE; }; ... }
  • 7. my $data = do { local $/; <DATA> }; ...; ! __END__ <?xml version="1.0"?> <root> ... </root>
  • 8. my $data = do { local $/; <DATA> }; ! s|.*(?=<elem>)||; s|(?<=</elem>).*||; ! my $name = m|<elem>(.*?)</elem>|; ! __END__ <?xml version="1.0"?> <root> ...<elem>Buster</elem> </root>
  • 9. $g = q("Mimi","Bean,Buster","Roscoe"); ! my @gatos = split /(?<="),(?=")/, $g;
  • 10. $g = q("Roscoe "","" Cat","Bean, Buster"); ! my @gatos = split /(?<!"")(?<="),(?=")(?!"")/, $g;
  • 11. if( ref $r eq 'ARRAY' ) ! if( ref $r eq ref [] ) ! if( ref $r eq ref {} ) ! if( ref $r eq ref sub {} ) ! if( ref $r eq ref qr// )
  • 12. join "n", @entries, ''; ! join "nt", "t", @entries;
  • 13. BEGIN { use Foo; package Foo; no warnings qw(redefine); sub foo { ... } }
  • 14. # Git::CPAN::Patch ! % git cpan-init http://... ... hack hack hack ... % git commit % git cpan-sendpatch
  • 15. my $file = MPEG::Info->new( ... ); ! print join $/, map { $file->$_() } qw(acodec acodecraw achans ... );
  • 16. package Modulino { run(@ARGV) unless caller; ! sub run { my @args = @_; ...; } ! }
  • 17. if( /p{IsUppercaseRoman}/ ) { ...} ! # Ⅰ Ⅴ Ⅹ Ⅼ Ⅽ Ⅾ Ⅿ ↁ ↂ ↇ ↈ sub IsUppercaseRoman { return <<"CODE_NUMBERS"; 2160 2164 2169 216C 216F 2181 2182 2187 2188 CODE_NUMBERS }
  • 18. printf '%1$#b %1$#o %1$d %1$#xn", 137; ! ! # 0b10001001 0211 137 0x89
  • 19. gato( name => 'Buster' ); ! sub gato { my %defaults = (...); my %config = (%defaults, @_ ); ...; }
  • 20. BEGIN { my $fixed_time = 1234567890; no warnings qw(redefine); ! *CORE::GLOBAL::time = sub { $fixed_time }; ! sub set_time { $fixed_time = $_[0] } } ! ok( time > $fixed_time );
  • 21. sub my_grep (&@) { my( $sub ) = shift; foreach my $arg ( @_ ) { local $_ = $arg; push @output, $arg if $sub->() } }
  • 22. my $ucfirst_and_trim = composer( &trim_front, &trim_back, &my_ucfirst ); ! $s = $ucfirst_and_trim->($s);
  • 23. sub composer { my (@sub_refs) = @_; sub { my $string = shift; foreach my $sub_ref (@sub_refs) { $string = $sub_ref->($string); } return $string; }; }
  • 24. my @tests = ( # ARG EXPECTED LABEL [ [1,2,3], 6, 'Sum is 6' ], [ [-1,0,9], 8, 'Sum is 8' ], ... ); ! foreach my $test ( @tests ) { is( target_sub( $test->[ARG] ), $test->[EXPECTED], $test->[LABEL] ); }
  • 25. package Local::Null::Logger { sub new { bless my $x, $_[0] } sub AUTOLOAD { shift; print @_, $/ } sub DESTROY { 1 } } ! sub _init_logger { my $log4perl_loaded = eval "require Log::Log4perl; 1"; unless( $log4perl_loaded ){ return Local::Null::Logger->new; } ...; }
  • 26. $object->foo->bar->baz->quux; ! package Class { sub bar { return Null->new if $error; } } ! package Null { my $null = bless {}, __PACKAGE__; sub new { $null } sub AUTOLOAD { return $_[0] } sub DESTROY { 1 } }