From: Matt S Trout Date: Fri, 4 Dec 2015 21:31:10 +0000 (+0000) Subject: significantly prettier deparses X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=061f9d55dea832c461ac979bbf09d285f56c24e0;p=scpubgit%2FDX.git significantly prettier deparses --- diff --git a/lib/DX/Deparse.pm b/lib/DX/Deparse.pm index b94163d..df624c5 100644 --- a/lib/DX/Deparse.pm +++ b/lib/DX/Deparse.pm @@ -36,6 +36,8 @@ sub _fmt_value_dict { map [ $_, $dict->get_member_at($_) ], $dict->index_list ], $meta); return '{{ }}' unless $chunks =~ /\S/; + s/^\s+//, s/\n\s+/ /g for (my $maybe = $chunks); + return "{{ ${maybe} }}" if length($maybe) < $meta->{width_left}; "{{\n${chunks}\n}}"; } @@ -70,6 +72,8 @@ sub _fmt_object { my ($self, $pairs, $meta) = @_; my $chunks = $self->_fmt_pairs($pairs, $meta); return '{ }' unless $chunks =~ /\S/; + s/^\s+//, s/\n\s+/ /g for (my $maybe = $chunks); + return "{ ${maybe} }" if length($maybe) < $meta->{width_left}; "{\n${chunks}\n}" } @@ -116,11 +120,20 @@ sub _fmt_resolvedpropositionset { my ($self, $rps, $meta) = @_; $self->_fmt_object([ map { - [ $_, $rps->dependencies_for($_) ] + [ $_, [ + map bless([ @$_ ], 'DX::Dependency'), + map @{$_}[1..$#$_], + @{$rps->dependencies_for($_)} + ] ] } @{$rps->propositions}, ], $meta); } +sub _fmt_dependency { + my ($self, $dep, $meta) = @_; + '{ '.join(' ', map $self->_fmt($_, $meta), @$dep).' }' +} + sub _fmt_proposition { my ($self, $prop, $meta) = @_; join ' ',