10 my ($self, $ometa) = @_;
11 +{ %$ometa, width_left => $ometa->{width_left} - length $self->indent_by };
15 my ($self, $to_indent) = @_;
16 $to_indent =~ s/^/${\$self->indent_by}/mg;
21 my ($self, $thing) = @_;
22 $self->_fmt($thing, { width_left => $self->max_width })."\n";
26 my ($self, $thing, $meta) = @_;
27 return '{}' unless defined($thing);
28 return $thing unless ref($thing);
29 my $type = join'_', split '::', lc +(ref($thing) =~ /^(?:DX::)?(.*)/)[0];
30 $self->${\"_fmt_${type}"}($thing, $meta);
33 sub _fmt_error_typetiny_assertion {
38 my ($self, $dict, $meta) = @_;
39 my $chunks = $self->_fmt_pairs([
40 map [ $_, $dict->get_member_at($_) ], $dict->index_list
42 return '{{ }}' unless $chunks =~ /\S/;
43 s/^\s+//, s/\n\s+/ /g for (my $maybe = $chunks);
44 return "{{ ${maybe} }}" if length($maybe) < $meta->{width_left};
49 my ($self, $pairs, $ometa) = @_;
50 my $imeta = $self->_inner_meta($ometa);
51 $self->_indent_one(join "\n", map {
52 join ' ', map $self->_fmt($_, $imeta), @$_
56 sub _fmt_value_string {
57 my ($self, $string) = @_;
58 # TODO: multiline handling
59 my $val = $string->string_value;
60 if ($val =~ /^\w+$/) {
67 sub _fmt_value_number { $_[1]->number_value }
69 sub _fmt_value_true { 'true' }
71 sub _fmt_value_false { 'false' }
73 sub _fmt_value_unset { 'unset' }
76 my ($self, $pairs, $meta) = @_;
77 my $chunks = $self->_fmt_pairs($pairs, $meta);
78 return '{ }' unless $chunks =~ /\S/;
79 s/^\s+//, s/\n\s+/ /g for (my $maybe = $chunks);
80 return "{ ${maybe} }" if length($maybe) < $meta->{width_left};
85 my ($self, $hyp, $meta) = @_;
87 map [ $_ => $hyp->$_ ],
88 qw(actions resolved_propositions scope)
93 my ($self, $ary, $ometa) = @_;
94 my $imeta = $self->_inner_meta($ometa);
95 my $chunks = $self->_indent_one(
96 join "\n", map $self->_fmt($_, $imeta), @$ary
98 return '{ }' unless $chunks =~ /\S/;
103 my ($self, $glob, $meta) = @_;
104 return ((''.*$glob) =~ /::([A-Z_]+)$/)[0];
107 sub _fmt_action_setvalue {
108 my ($self, $action, $meta) = @_;
109 $self->_fmt_action_generic(SetValue => $action, $meta);
112 sub _fmt_action_addvalue {
113 my ($self, $action, $meta) = @_;
114 $self->_fmt_action_generic(AddValue => $action, $meta);
117 sub _fmt_action_bindvalue {
118 my ($self, $action, $meta) = @_;
119 my $path = join '.', map $self->_fmt($_, $meta), @{$action->target_path};
120 my $bound_path = join '.',
121 map $self->_fmt($_, $meta),
124 ->inner_action_builder
126 join ' ', BindValue => $path, $bound_path;
129 sub _fmt_action_addboundvalue {
130 my ($self, $action, $meta) = @_;
131 $self->_fmt_action_generic(AddBoundValue => $action, $meta);
134 sub _fmt_action_setboundvalue {
135 my ($self, $action, $meta) = @_;
136 $self->_fmt_action_generic(SetBoundValue => $action, $meta);
139 sub _fmt_action_generic {
140 my ($self, $name, $action, $meta) = @_;
141 my $path = join '.', map $self->_fmt($_, $meta), @{$action->target_path};
142 join ' ', $name, $path, $self->_fmt($action->new_value, $meta);
145 sub _fmt_resolvedpropositionset {
146 my ($self, $rps, $meta) = @_;
150 map bless([ @$_ ], 'DX::Dependency'),
152 @{$rps->dependencies_for($_)}
154 } @{$rps->propositions},
158 sub _fmt_dependency {
159 my ($self, $dep, $meta) = @_;
160 '{ '.join(' ', map $self->_fmt($_, $meta), @$dep).' }'
163 sub _fmt_proposition {
164 my ($self, $prop, $meta) = @_;
167 map $self->_fmt($_, $meta),
168 map +((!ref($_) and $prop->introduced_names->{$_}) ? "?$_" : $_),
173 my ($self, $scope, $meta) = @_;
175 [ W => $scope->globals ],
176 map [ $_ => $scope->locals->[$_] ], 0..$#{$scope->locals}
180 sub _fmt_searchstate {
181 my ($self, $ss, $meta) = @_;
183 [ adjustments_made => '{...}' ],
184 [ current_hypothesis => $ss->current_hypothesis ],
188 sub _fmt_step_considerproposition {
189 my ($self, $step, $meta) = @_;
190 'consider '.$self->_fmt($step->proposition, $meta);
193 sub _fmt_step_resolveproposition {
194 my ($self, $step, $meta) = @_;
195 'resolve '.$self->_fmt_object([
196 [ actions => $step->actions ],
197 ($step->alternative_step
198 ? [ alternative_step => '...' ]
201 map bless([ @$_ ], 'DX::Dependency'),
208 sub _fmt_step_backtrack { 'backtrack' }
210 sub _fmt_step_markassolution { 'mark as solution' }
212 sub _fmt_step_enterrecheck {
213 my ($self, $step, $meta) = @_;
214 'recheck '.$self->_fmt($step->proposition_list->[0], $meta);
217 sub _fmt_step_completerecheck { 'complete recheck' }
219 sub _fmt_step_failrecheck { 'fail recheck' }