| 1 | package Langertha::Result; | ||||||||||||||||||||||
| 2 | # ABSTRACT: Common result object for Raider and Raid execution | ||||||||||||||||||||||
| 3 | 8 | our $VERSION = '0.502'; | |||||||||||||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | use overload | ||||||||||||||||||||||
| 7 | 6 | ▶ | '""' => sub { $_[0]->text // '' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->text // ""
MC/DC100%1/1
$_[0]->text // ""
$_[0]->text
Truth table100%2/2
A
A= $_[0]->text
| |||||||||||||||||||||||
| 8 | 8 | ▶ | fallback => 1; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 8 | has type => ( | |||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||
| 13 | isa => 'Str', | ||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 8 | has text => ( | |||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||
| 20 | isa => 'Str', | ||||||||||||||||||||||
| 21 | predicate => 'has_text', | ||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 8 | has content => ( | |||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||
| 27 | isa => 'Str', | ||||||||||||||||||||||
| 28 | predicate => 'has_content', | ||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | 8 | has options => ( | |||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||
| 34 | isa => 'ArrayRef', | ||||||||||||||||||||||
| 35 | predicate => 'has_options', | ||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 8 | has data => ( | |||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||
| 41 | predicate => 'has_data', | ||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 8 | has context => ( | |||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||
| 47 | predicate => 'has_context', | ||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | 39 | ▶ | sub is_final { $_[0]->type eq 'final' } | ||||||||||||||||||||
|
Subroutine
is_final: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 52 | 10 | ▶ | sub is_question { $_[0]->type eq 'question' } | ||||||||||||||||||||
|
Subroutine
is_question: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 53 | 7 | ▶ | sub is_pause { $_[0]->type eq 'pause' } | ||||||||||||||||||||
|
Subroutine
is_pause: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 54 | 15 | ▶ | sub is_abort { $_[0]->type eq 'abort' } | ||||||||||||||||||||
|
Subroutine
is_abort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | sub as_hash { | ||||||||||||||||||||||
| 58 | 62 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||
|
Subroutine
as_hash: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||
| 59 | return { | ||||||||||||||||||||||
| 60 | 62 | ▶ | type => $self->type, | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 61 | ($self->has_text ? ( text => $self->text ) : ()), | ||||||||||||||||||||||
| 62 | ($self->has_content ? ( content => $self->content ) : ()), | ||||||||||||||||||||||
| 63 | ($self->has_options ? ( options => $self->options ) : ()), | ||||||||||||||||||||||
| 64 | ($self->has_data ? ( data => $self->data ) : ()), | ||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | sub with_context { | ||||||||||||||||||||||
| 70 | 30 | ▶ | my ( $self, $context ) = @_; | ||||||||||||||||||||
|
Subroutine
with_context: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 71 | return ref($self)->new( | ||||||||||||||||||||||
| 72 | 30 | %{$self->as_hash}, | |||||||||||||||||||||
| 73 | context => $context, | ||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | sub final { | ||||||||||||||||||||||
| 79 | 39 | ▶ | my ( $class, $text, %args ) = @_; | ||||||||||||||||||||
|
Subroutine
final: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||
| 80 | 39 | ▶ | return $class->new( | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 81 | type => 'final', | ||||||||||||||||||||||
| 82 | (defined $text ? ( text => "$text" ) : ()), | ||||||||||||||||||||||
| 83 | %args, | ||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | sub question { | ||||||||||||||||||||||
| 88 | 2 | ▶ | my ( $class, $content, %args ) = @_; | ||||||||||||||||||||
|
Subroutine
question: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 89 | 2 | return $class->new( | |||||||||||||||||||||
| 90 | type => 'question', | ||||||||||||||||||||||
| 91 | content => "$content", | ||||||||||||||||||||||
| 92 | %args, | ||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | sub pause { | ||||||||||||||||||||||
| 97 | 1 | ▶ | my ( $class, $content, %args ) = @_; | ||||||||||||||||||||
|
Subroutine
pause: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 98 | 1 | return $class->new( | |||||||||||||||||||||
| 99 | type => 'pause', | ||||||||||||||||||||||
| 100 | content => "$content", | ||||||||||||||||||||||
| 101 | %args, | ||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | sub abort { | ||||||||||||||||||||||
| 106 | 4 | ▶ | my ( $class, $content, %args ) = @_; | ||||||||||||||||||||
|
Subroutine
abort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 107 | 4 | return $class->new( | |||||||||||||||||||||
| 108 | type => 'abort', | ||||||||||||||||||||||
| 109 | content => "$content", | ||||||||||||||||||||||
| 110 | %args, | ||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 8 | 1; | |||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | =pod | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =encoding UTF-8 | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | =head1 NAME | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | Langertha::Result - Common result object for Raider and Raid execution | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | =head1 VERSION | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | version 0.502 | ||||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | my $r = Langertha::Result->final('done'); | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | if ($r->is_question) { | ||||||||||||||||||||||
| 138 | ... | ||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | say "$r"; # stringifies to text (or empty string) | ||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | Unified result type used by runnable nodes in Langertha orchestration. | ||||||||||||||||||||||
| 146 | Represents one of four high-level outcomes: | ||||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | =over 4 | ||||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | =item * C<final> - successful completion | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | =item * C<question> - needs user input | ||||||||||||||||||||||
| 153 | |||||||||||||||||||||||
| 154 | =item * C<pause> - intentionally paused / resumable | ||||||||||||||||||||||
| 155 | |||||||||||||||||||||||
| 156 | =item * C<abort> - explicit stop / error | ||||||||||||||||||||||
| 157 | |||||||||||||||||||||||
| 158 | =back | ||||||||||||||||||||||
| 159 | |||||||||||||||||||||||
| 160 | L<Langertha::Raider::Result> subclasses this class for backward-compatible | ||||||||||||||||||||||
| 161 | Raider behavior. | ||||||||||||||||||||||
| 162 | |||||||||||||||||||||||
| 163 | =head2 type | ||||||||||||||||||||||
| 164 | |||||||||||||||||||||||
| 165 | Result type: C<final>, C<question>, C<pause>, or C<abort>. | ||||||||||||||||||||||
| 166 | |||||||||||||||||||||||
| 167 | =head2 text | ||||||||||||||||||||||
| 168 | |||||||||||||||||||||||
| 169 | Final output text, usually used with C<type =E<gt> final>. | ||||||||||||||||||||||
| 170 | |||||||||||||||||||||||
| 171 | =head2 content | ||||||||||||||||||||||
| 172 | |||||||||||||||||||||||
| 173 | Auxiliary text payload for non-final outcomes (question/pause/abort). | ||||||||||||||||||||||
| 174 | |||||||||||||||||||||||
| 175 | =head2 options | ||||||||||||||||||||||
| 176 | |||||||||||||||||||||||
| 177 | Optional choices for question-style results. | ||||||||||||||||||||||
| 178 | |||||||||||||||||||||||
| 179 | =head2 data | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | Optional structured payload for callers/orchestrators. | ||||||||||||||||||||||
| 182 | |||||||||||||||||||||||
| 183 | =head2 context | ||||||||||||||||||||||
| 184 | |||||||||||||||||||||||
| 185 | Optional run context attached to the result. | ||||||||||||||||||||||
| 186 | |||||||||||||||||||||||
| 187 | =head2 is_final | ||||||||||||||||||||||
| 188 | |||||||||||||||||||||||
| 189 | Returns true for C<type =E<gt> final>. | ||||||||||||||||||||||
| 190 | |||||||||||||||||||||||
| 191 | =head2 is_question | ||||||||||||||||||||||
| 192 | |||||||||||||||||||||||
| 193 | Returns true for C<type =E<gt> question>. | ||||||||||||||||||||||
| 194 | |||||||||||||||||||||||
| 195 | =head2 is_pause | ||||||||||||||||||||||
| 196 | |||||||||||||||||||||||
| 197 | Returns true for C<type =E<gt> pause>. | ||||||||||||||||||||||
| 198 | |||||||||||||||||||||||
| 199 | =head2 is_abort | ||||||||||||||||||||||
| 200 | |||||||||||||||||||||||
| 201 | Returns true for C<type =E<gt> abort>. | ||||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | =head2 as_hash | ||||||||||||||||||||||
| 204 | |||||||||||||||||||||||
| 205 | Returns a plain hashref representation (without C<context>). | ||||||||||||||||||||||
| 206 | |||||||||||||||||||||||
| 207 | =head2 with_context | ||||||||||||||||||||||
| 208 | |||||||||||||||||||||||
| 209 | my $with_ctx = $result->with_context($ctx); | ||||||||||||||||||||||
| 210 | |||||||||||||||||||||||
| 211 | Returns a cloned result object with C<context> attached. | ||||||||||||||||||||||
| 212 | |||||||||||||||||||||||
| 213 | =head2 final | ||||||||||||||||||||||
| 214 | |||||||||||||||||||||||
| 215 | my $r = Langertha::Result->final('ok'); | ||||||||||||||||||||||
| 216 | |||||||||||||||||||||||
| 217 | Constructor helper for final results. | ||||||||||||||||||||||
| 218 | |||||||||||||||||||||||
| 219 | =head2 question | ||||||||||||||||||||||
| 220 | |||||||||||||||||||||||
| 221 | my $r = Langertha::Result->question('Which option?', options => ['a','b']); | ||||||||||||||||||||||
| 222 | |||||||||||||||||||||||
| 223 | Constructor helper for question results. | ||||||||||||||||||||||
| 224 | |||||||||||||||||||||||
| 225 | =head2 pause | ||||||||||||||||||||||
| 226 | |||||||||||||||||||||||
| 227 | my $r = Langertha::Result->pause('Waiting for external event'); | ||||||||||||||||||||||
| 228 | |||||||||||||||||||||||
| 229 | Constructor helper for pause results. | ||||||||||||||||||||||
| 230 | |||||||||||||||||||||||
| 231 | =head2 abort | ||||||||||||||||||||||
| 232 | |||||||||||||||||||||||
| 233 | my $r = Langertha::Result->abort('Cannot continue'); | ||||||||||||||||||||||
| 234 | |||||||||||||||||||||||
| 235 | Constructor helper for abort results. | ||||||||||||||||||||||
| 236 | |||||||||||||||||||||||
| 237 | =head1 SUPPORT | ||||||||||||||||||||||
| 238 | |||||||||||||||||||||||
| 239 | =head2 Issues | ||||||||||||||||||||||
| 240 | |||||||||||||||||||||||
| 241 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||
| 242 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||
| 243 | |||||||||||||||||||||||
| 244 | =head2 IRC | ||||||||||||||||||||||
| 245 | |||||||||||||||||||||||
| 246 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||
| 247 | |||||||||||||||||||||||
| 248 | =head1 CONTRIBUTING | ||||||||||||||||||||||
| 249 | |||||||||||||||||||||||
| 250 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||
| 251 | |||||||||||||||||||||||
| 252 | =head1 AUTHOR | ||||||||||||||||||||||
| 253 | |||||||||||||||||||||||
| 254 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||
| 255 | |||||||||||||||||||||||
| 256 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 257 | |||||||||||||||||||||||
| 258 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||
| 259 | |||||||||||||||||||||||
| 260 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||
| 261 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||
| 262 | |||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||