Created
June 20, 2019 21:35
-
-
Save nkh/f8d41e0748c325efc64dae0b0f24f142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Data::Dump::Tree ; | |
use Data::Dump::Tree::Enums ; | |
use Data::Dump::Tree::ExtraRoles ; | |
use Terminal::ANSIColor ; | |
use LWP::Simple; | |
use DOM::Tiny ; | |
my @colors = < on_240 on_241 on_244 on_245 on_254 on_230 on_136 on_166 on_160 on_125 on_61 on_33 on_37 on_64 > ; | |
my @colors_fg = < 0 > ; | |
my $t0 = now ; | |
my $html = DOM::Tiny.parse(LWP::Simple.get("http://www.google.com")); | |
"parsing: {now - $t0} s".say ; | |
my $d = Data::Dump::Tree.new: | |
:!color, | |
#:color_filters[&color_background], | |
:nl ;#:elements_filters[&final_first, &non_final_no_binder] ; | |
$t0 = now ; | |
$d.ddt: $html ; | |
"rendering: {now - $t0} s".say ; | |
sub final_first($dumper, $, $, @sub_elements) | |
{ | |
@sub_elements = @sub_elements.sort: { $dumper.get_element_header($^a[2])[2] !~~ DDT_FINAL } | |
} | |
sub non_final_no_binder ($dumper, $, $, @sub_elements) | |
{ | |
for @sub_elements -> ($k, $binder is rw, $value, $) | |
{ | |
$binder = '' if $dumper.get_element_header($value)[2] !~~ DDT_FINAL ; | |
} | |
} | |
multi sub color_background($dumper, $s, $depth, $path, $key, @glyphs, \override_color, @reset_color) | |
{ | |
my $color = color(@colors[$depth % @colors.elems]) ~ color(@colors_fg[$depth % @colors_fg.elems]) ; | |
@reset_color.push: (color('reset'), '' , '') ; | |
my ($glyph_width, $glyph, $continuation_glyph, $multi_line_glyph, $empty_glyph, $filter_glyph) = @glyphs ; | |
$glyph = ($color, |$glyph[1..2]) ; | |
$continuation_glyph = ($color, |$continuation_glyph[1..2]) ; | |
$multi_line_glyph = ($color, |$multi_line_glyph[1..2]) ; | |
$empty_glyph = ($color, |$empty_glyph[1..2]) ; | |
$filter_glyph = ($color, |$filter_glyph[1..2]) ; | |
@glyphs = ($glyph_width, $glyph, $continuation_glyph, $multi_line_glyph, $empty_glyph, $filter_glyph) ; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment