| 1 | package Logic::Relational::Solution; | ||||||||||||
| 2 | |||||||||||||
| 3 | 27 | ▶ | use v5.38; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 27 | ▶ | use experimental 'signatures'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | Logic::Relational::Solution - Represents a single solution from a logic query. | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||
| 11 | |||||||||||||
| 12 | my $solution = $query->next; | ||||||||||||
| 13 | if ($solution) { | ||||||||||||
| 14 | say $solution->value($wanted_var); | ||||||||||||
| 15 | } | ||||||||||||
| 16 | |||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||
| 18 | |||||||||||||
| 19 | C<Logic::Relational::Solution> provides access to the variable bindings of a | ||||||||||||
| 20 | successful query execution. | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 METHODS | ||||||||||||
| 23 | |||||||||||||
| 24 | =head2 new | ||||||||||||
| 25 | |||||||||||||
| 26 | Constructor. Takes C<substitution>. | ||||||||||||
| 27 | |||||||||||||
| 28 | =head2 substitution | ||||||||||||
| 29 | |||||||||||||
| 30 | Returns the substitution object for this solution. | ||||||||||||
| 31 | |||||||||||||
| 32 | =head2 value | ||||||||||||
| 33 | |||||||||||||
| 34 | Takes a variable and returns its reified (fully instantiated) value in this solution. | ||||||||||||
| 35 | |||||||||||||
| 36 | =cut | ||||||||||||
| 37 | |||||||||||||
| 38 | 27 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | |||||||||||||
| 40 | 419 | ▶ | sub new ( $class, %args ) { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||
| 41 | 419 | ▶ | my $subst = $args{substitution} // croak "substitution is required"; | ||||||||||
|
Condition50%1/2
$args{"substitution"} // croak("substitution is required")
MC/DC0%0/1
$args{"substitution"} // croak("substitution is required")
$args{"substitution"}
Truth table50%1/2
A
A= $args{"substitution"}
| |||||||||||||
| 42 | 419 | return bless { substitution => $subst }, $class; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 75 | ▶ | sub substitution ($self) { | ||||||||||
|
Subroutine
substitution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 46 | 75 | return $self->{substitution}; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 236 | ▶ | sub value ( $self, $var ) { | ||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 50 | 236 | return $self->{substitution}->reify($var); | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 27 | 1; | |||||||||||