blib/lib/Langertha/Raider/Result.pm

filter: Statementstmt 100% 37 / 37 Branchbran 80.0% 8 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 16 / 16 Podpod 100% 12 / 12 totaltotal 97.4% 76 / 78 CC 7 SCAR 7.4
CC
7
Cov
96%
as_hash
5.0
final
2.1
__ANON__
2.0
CRAP 2.1
« blib/lib/Langertha/Raider/Instructions.pm ↑ Summary blib/lib/Langertha/Raider/Binary.pm »
1 package Langertha::Raider::Result;
2 # ABSTRACT: Result object for Raider and Raid execution
3 99 our $VERSION = '0.503';
4 99 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use overload
7 145 ▶ '""' => sub { $_[0]->text // '' },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->text // ""
l!l
1423
MC/DC100%1/1
$_[0]->text // ""
$_[0]->text
Truth table100%2/2
A
A= $_[0]->text
Aresult
11
00
8 # An object that exists is true. Without this, `fallback => 1` derives bool
9 # from the '""' overload, and every text-less result -- question, pause,
10 # abort, which carry `content` rather than `text` -- would be false. See
11 # "Boolean context" (karr #100).
12 18 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 99 fallback => 1;
14  
15  
16 99 has type => (
17 is => 'ro',
18 isa => 'Str',
19 required => 1,
20 );
21  
22  
23 99 has text => (
24 is => 'ro',
25 isa => 'Str',
26 predicate => 'has_text',
27 );
28  
29  
30 99 has content => (
31 is => 'ro',
32 isa => 'Str',
33 predicate => 'has_content',
34 );
35  
36  
37 99 has options => (
38 is => 'ro',
39 isa => 'ArrayRef',
40 predicate => 'has_options',
41 );
42  
43  
44 99 has data => (
45 is => 'ro',
46 predicate => 'has_data',
47 );
48  
49  
50 99 has context => (
51 is => 'ro',
52 predicate => 'has_context',
53 );
54  
55  
56 80 ▶sub is_final { $_[0]->type eq 'final' }
Subroutine is_final: called CC=1 SCAR=0.0
Pod documented
57 26 ▶sub is_question { $_[0]->type eq 'question' }
Subroutine is_question: called CC=1 SCAR=0.0
Pod documented
58 9 ▶sub is_pause { $_[0]->type eq 'pause' }
Subroutine is_pause: called CC=1 SCAR=0.0
Pod documented
59 24 ▶sub is_abort { $_[0]->type eq 'abort' }
Subroutine is_abort: called CC=1 SCAR=0.0
Pod documented
60 87 ▶sub is_cancelled { $_[0]->type eq 'cancelled' }
Subroutine is_cancelled: called CC=1 SCAR=0.0
Pod documented
61  
62  
63 73 ▶sub as_hash {
Subroutine as_hash: called CC=5 SCAR=16.1
Pod documented
64 73 my ( $self ) = @_;
65 return {
66 73 ▶ type => $self->type,
Branch: 4 branches
BranchTrueFalseTotal
$self->has_text ? : 48 25 73
$self->has_content ? : 25 48 73
$self->has_options ? : 0 73 73
$self->has_data ? : 5 68 73
67 ($self->has_text ? ( text => $self->text ) : ()),
68 ($self->has_content ? ( content => $self->content ) : ()),
69 ($self->has_options ? ( options => $self->options ) : ()),
70 ($self->has_data ? ( data => $self->data ) : ()),
71 };
72 }
73  
74  
75 36 ▶sub with_context {
Subroutine with_context: called CC=1 SCAR=0.0
Pod documented
76 36 my ( $self, $context ) = @_;
77 return ref($self)->new(
78 36 %{$self->as_hash},
79 context => $context,
80 );
81 }
82  
83  
84 43 ▶sub final {
Subroutine final: called CC=2 SCAR=7.2
Pod documented
85 43 my ( $class, $text, %args ) = @_;
86 43 ▶ return $class->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 43 0 43
87 type => 'final',
88 (defined $text ? ( text => "$text" ) : ()),
89 %args,
90 );
91 }
92  
93 3 ▶sub question {
Subroutine question: called CC=1 SCAR=0.0
Pod documented
94 3 my ( $class, $content, %args ) = @_;
95 3 return $class->new(
96 type => 'question',
97 content => "$content",
98 %args,
99 );
100 }
101  
102 2 ▶sub pause {
Subroutine pause: called CC=1 SCAR=0.0
Pod documented
103 2 my ( $class, $content, %args ) = @_;
104 2 return $class->new(
105 type => 'pause',
106 content => "$content",
107 %args,
108 );
109 }
110  
111 5 ▶sub abort {
Subroutine abort: called CC=1 SCAR=0.0
Pod documented
112 5 my ( $class, $content, %args ) = @_;
113 5 return $class->new(
114 type => 'abort',
115 content => "$content",
116 %args,
117 );
118 }
119  
120 19 ▶sub cancelled {
Subroutine cancelled: called CC=1 SCAR=0.0
Pod documented
121 19 my ( $class, $content, %args ) = @_;
122 19 return $class->new(
123 type => 'cancelled',
124 content => "$content",
125 %args,
126 );
127 }
128  
129  
130 99 __PACKAGE__->meta->make_immutable;
131  
132 99 1;
133  
134 __END__
135  
136 =pod
137  
138 =encoding UTF-8
139  
140 =head1 NAME
141  
142 Langertha::Raider::Result - Result object for Raider and Raid execution
143  
144 =head1 VERSION
145  
146 version 0.503
147  
148 =head1 SYNOPSIS
149  
150 my $r = Langertha::Raider::Result->final('done');
151  
152 if ($r->is_question) {
153 ...
154 }
155  
156 say "$r"; # stringifies to text (or empty string)
157  
158 =head1 DESCRIPTION
159  
160 Unified result type returned by L<Langertha::Raider> and the L<Langertha::Raid>
161 orchestration nodes.
162 Represents one of five high-level outcomes:
163  
164 =over 4
165  
166 =item * C<final> - successful completion
167  
168 =item * C<question> - needs user input
169  
170 =item * C<pause> - intentionally paused / resumable
171  
172 =item * C<abort> - explicit stop / error
173  
174 =item * C<cancelled> - stopped from outside (L<Langertha::Raider/cancel>)
175  
176 =back
177  
178 =head2 Boolean context — a Result is always true
179  
180 C<Langertha::Raider::Result> overloads C<bool> to a constant true: the object exists,
181 so it is true, whatever L</text> happens to hold. With only the C<""> overload
182 and C<fallback =E<gt> 1>, Perl derives boolean context from stringification,
183 and a C<question>, C<pause> or C<abort> carries its message in L</content>
184 rather than L</text> — so every result that actually needs handling was
185 B<false>, and a caller writing
186  
187 my $r = $raider->raid(@messages);
188 if ($r) { ... } # entered now; silently skipped before
189  
190 dropped exactly those. The same applied to a C<final> whose text is C<"0">.
191 Decided in karr #100, together with the identical fix on
192 L<Langertha::Response/"Boolean context — a Response is always true">.
193  
194 Type is still asked with the predicates (L</is_final>, L</is_question>,
195 L</is_pause>, L</is_abort>), and emptiness of the text with C<length "$r">
196 or C<has_text>. The C<""> overload is unchanged: C<"$r"> is still L</text>
197 (or the empty string), and C<eq> / C<ne> / concatenation keep routing
198 through it.
199  
200 =head2 type
201  
202 Result type: C<final>, C<question>, C<pause>, C<abort> or C<cancelled>.
203  
204 =head2 text
205  
206 Final output text, usually used with C<type =E<gt> final>.
207  
208 =head2 content
209  
210 Auxiliary text payload for non-final outcomes (question/pause/abort/cancelled).
211  
212 =head2 options
213  
214 Optional choices for question-style results.
215  
216 =head2 data
217  
218 Optional structured payload for callers/orchestrators.
219  
220 =head2 context
221  
222 Optional run context attached to the result.
223  
224 =head2 is_final
225  
226 Returns true for C<type =E<gt> final>.
227  
228 =head2 is_question
229  
230 Returns true for C<type =E<gt> question>.
231  
232 =head2 is_pause
233  
234 Returns true for C<type =E<gt> pause>.
235  
236 =head2 is_abort
237  
238 Returns true for C<type =E<gt> abort>.
239  
240 =head2 is_cancelled
241  
242 Returns true for C<type =E<gt> cancelled>.
243  
244 =head2 as_hash
245  
246 Returns a plain hashref representation (without C<context>).
247  
248 =head2 with_context
249  
250 my $with_ctx = $result->with_context($ctx);
251  
252 Returns a cloned result object with C<context> attached.
253  
254 =head2 final
255  
256 my $r = Langertha::Raider::Result->final('ok');
257  
258 Constructor helper for final results.
259  
260 =head2 question
261  
262 my $r = Langertha::Raider::Result->question('Which option?', options => ['a','b']);
263  
264 Constructor helper for question results.
265  
266 =head2 pause
267  
268 my $r = Langertha::Raider::Result->pause('Waiting for external event');
269  
270 Constructor helper for pause results.
271  
272 =head2 abort
273  
274 my $r = Langertha::Raider::Result->abort('Cannot continue');
275  
276 Constructor helper for abort results.
277  
278 =head2 cancelled
279  
280 my $r = Langertha::Raider::Result->cancelled('Cancelled');
281  
282 Constructor helper for cancelled results.
283  
284 =head1 SUPPORT
285  
286 =head2 Issues
287  
288 Please report bugs and feature requests on GitHub at
289 L<https://github.com/Getty/langertha-raider/issues>.
290  
291 =head2 IRC
292  
293 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
294  
295 =head1 CONTRIBUTING
296  
297 Contributions are welcome! Please fork the repository and submit a pull request.
298  
299 =head1 AUTHOR
300  
301 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
302  
303 =head1 COPYRIGHT AND LICENSE
304  
305 This software is copyright (c) 2026 by Torsten Raudssus.
306  
307 This is free software; you can redistribute it and/or modify it under
308 the same terms as the Perl 5 programming language system itself.
309  
310 =cut
« blib/lib/Langertha/Raider/Instructions.pm ↑ Summary blib/lib/Langertha/Raider/Binary.pm »