SlideShare a Scribd company logo
1 of 24
Download to read offline
Dumping
Perl 6
London.pm
29 Jun 2017
ThePerlReview•www.theperlreview.com
DumpingPerl6
Sponsored in part by a grant from
ThePerlReview•www.theperlreview.com
DumpingPerl6
Arranged by
ThePerlReview•www.theperlreview.com
DumpingPerl6
Not Data::Dumper
• Does not produce eval-able code
• Does not know what it has already seen
• Missing a few formatting features
ThePerlReview•www.theperlreview.com
DumpingPerl6
Plain
my $rx = rx/ <[ a .. z ]> <[ 1 .. 9 ]> /;
my $string = ':::abc123::';
my $match = $string ~~ $rx;
put $match;
c1
ThePerlReview•www.theperlreview.com
DumpingPerl6
.gist
my $rx = rx/ <[ a .. z ]> <[ 1 .. 9 ]> /;
my $string = ':::abc123::';
my $match = $string ~~ $rx;
say $match; # put $match.gist
「c1」
ThePerlReview•www.theperlreview.com
DumpingPerl6
.perl
my $rx = rx/ <[ a .. z ]> <[ 1 .. 9 ]> /;
my $string = ':::abc123::';
my $match = $string ~~ $rx;
put $match.perl;
Match.new(list => (), made => Any,
pos => 7, hash => Map.new(()), orig =>
":::abc123::", from => 5)
ThePerlReview•www.theperlreview.com
DumpingPerl6
Pretty::Printer
use Pretty::Printer; # From Jeff Goff
my $rx = rx/ <[ a .. z ]> <[ 1 .. 9 ]> /;
my $string = ':::abc123::';
my $match = $string ~~ $rx;
Pretty::Printer.new.pp: $match;
Any
ThePerlReview•www.theperlreview.com
DumpingPerl6
method _pp($ds,$depth)
{
my Str $str;
given $ds.WHAT
{
when Hash { $str ~= self.Hash($ds,$depth) }
when Array { $str ~= self.Array($ds,$depth) }
when Pair { $str ~= self.Pair($ds,$depth) }
when Str { $str ~= $ds.perl }
when Numeric { $str ~= ~$ds }
when Nil { $str ~= q{Nil} }
when Any { $str ~= q{Any} }
}
return self.indent-string($str,$depth);
}
ThePerlReview•www.theperlreview.com
DumpingPerl6
PrettyDump
use PrettyDump;
my $rx = rx/ <[ a .. z ]> <[ 1 .. 9 ]> /;
my $string = ':::abc123::';
my $match = $string ~~ $rx;
put PrettyDump.new.dump: $match;
ThePerlReview•www.theperlreview.com
DumpingPerl6
Match.new(
:from(5),
:hash(Map.new()),
:list($()),
:made(Mu),
:orig(":::abc123::"),
:pos(7),
:to(7)
)
ThePerlReview•www.theperlreview.com
DumpingPerl6
By Type
ThePerlReview•www.theperlreview.com
DumpingPerl6
method _pp($ds,$depth)
{
my Str $str;
given $ds.WHAT
{
# Check more derived types first.
when Match { $str ~= self.Match($ds,$depth) }
when Hash { $str ~= self.Hash($ds,$depth) }
when Array { $str ~= self.Array($ds,$depth) }
when Map { $str ~= self.Map($ds,$depth) }
when List { $str ~= self.List($ds,$depth) }
when Pair { $str ~= self.Pair($ds,$depth) }
when Str { $str ~= $ds.perl }
when Numeric { $str ~= ~$ds }
when Nil { $str ~= q{Nil} }
when Any { $str ~= q{Any} }
}
return self.indent-string($str,$depth);
}
ThePerlReview•www.theperlreview.com
DumpingPerl6
Per Class
ThePerlReview•www.theperlreview.com
DumpingPerl6
class SomeClass {
…
method PrettyDump ( $pretty, $ds, $depth ) {
…
}
}
my $pretty = PrettyDump.new;
my $some-object = SomeClass.new;
put $pretty.dump: $some-object;
ThePerlReview•www.theperlreview.com
DumpingPerl6
use PrettyDump;
my $pretty = PrettyDump.new;
my Int $a = 137;
put $pretty.dump: $a;
my $b = $a but role {
method PrettyDump ( $pretty, $depth = 0 ) {
"({self.^name}) {self}";
}
};
put $pretty.dump: $b;
ThePerlReview•www.theperlreview.com
DumpingPerl6
method dump ( $ds, $depth = 0 ) {
put "In dump. Got ", $ds.^name;
my Str $str;
if $ds.can: 'PrettyDump' {
$str ~= $ds.PrettyDump: self;
}
elsif $ds ~~ Numeric {
$str ~= self.Numeric: $ds, $depth;
}
elsif self.can: $ds.^name {
my $what = $ds.^name;
$str ~= self."$what"( $ds, $depth );
}
else {
die "Could not handle " ~ $ds.perl;
}
return self.indent-string: $str, $depth;
}
ThePerlReview•www.theperlreview.com
DumpingPerl6
Per Object
ThePerlReview•www.theperlreview.com
DumpingPerl6
Decorate the Dumper
my $pretty = PrettyDump.new;
class SomeClass { … }
my $handler = sub ( $pretty, $ds, Int $depth = 0 ) {
...
}
$pretty.add-handler: 'SomeClass', $handler;
put $pretty.dump: $SomeClass-object;
ThePerlReview•www.theperlreview.com
DumpingPerl6
method dump ( $ds, Int $depth = 0 --> Str ) {
my Str $str = do {
# If the PrettyDump object has a user-defined handler
# for this type, prefer that one
if self.handles: $ds.^name {
self!handle: $ds, $depth;
}
# The object might have its own method to dump
# its structure
elsif $ds.can: 'PrettyDump' {
$ds.PrettyDump: self;
}
# If it's any sort of Numeric, we'll handle it
# and dispatch further
elsif $ds ~~ Numeric {
self!Numeric: $ds, $depth;
}
…
ThePerlReview•www.theperlreview.com
DumpingPerl6
# If we have a method name that matches the class, we'll
# use that.
elsif self.can: $ds.^name {
my $what = $ds.^name;
self."$what"( $ds, $depth );
}
# If the class inherits from something that we know
# about, use the most specific one that we know about
elsif $ds.^parents.grep(
{ self.can: $_.^name } ).elems > 0 {
my Str $str = '';
for $ds.^parents -> $type {
my $what = $type.^name;
next unless self.can( $what );
$str ~= self."$what"(
$ds, $depth, "{$ds.^name}.new(", ')' );
last;
}
$str;
}
…
ThePerlReview•www.theperlreview.com
DumpingPerl6
# If we're this far and the object has a .Str method,
# we'll use that:
elsif $ds.can: 'Str' {
"({$ds.^name}): " ~ $ds.Str;
}
# Finally, we'll put a placeholder method there
else {
"(Unhandled {$ds.^name})"
}
};
return self!indent-string: $str, $depth;
}
ThePerlReview•www.theperlreview.com
DumpingPerl6
What else might it do?
• Handle more data types
• Ignore some data types
• More configurable formatting options
• Formatting hooks
• Send email
ThePerlReview•www.theperlreview.com
DumpingPerl6
Questions

More Related Content

What's hot

Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet
 

What's hot (20)

The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
WordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryWordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know query
 
PHP 1
PHP 1PHP 1
PHP 1
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
Perl5i
Perl5iPerl5i
Perl5i
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
C99
C99C99
C99
 
Bioinformatics p5-bioperlv2014
Bioinformatics p5-bioperlv2014Bioinformatics p5-bioperlv2014
Bioinformatics p5-bioperlv2014
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
 

Similar to PrettyDump Perl 6 (London.pm)

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
 

Similar to PrettyDump Perl 6 (London.pm) (20)

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
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
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 

More from brian d foy

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
 

More from brian d foy (19)

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
 
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
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 
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
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginners
 
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
 
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
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

PrettyDump Perl 6 (London.pm)