| 1 | package Venus::Role::Testable; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 119 | ▶ | use 5.018; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 119 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 119 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # IMPORTS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 119 | ▶ | use Venus::Role 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # METHODS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | sub is_false { | ||||||||||||||||||||||||||
|
Subroutine
is_false: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 3 | my ($self, $code, @args) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | $code ||= $self->can('value') ? 'value' : sub{}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Branch: 1 branch
Condition33%1/3
$code ||= $self->can("value") ? "value" : sub {
}
MC/DC0%0/2
$code ||= $self->can("value") ? "value" : sub {
}
$code
$self->can("value") ? "value" : sub {
}
Truth table33%1/3
A ||= B
A= $codeB= $self->can("value") ? "value" : sub {
}
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | require Venus::Boolean; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | return $self->$code(@args) ? Venus::Boolean::FALSE() : Venus::Boolean::TRUE(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | sub is_true { | ||||||||||||||||||||||||||
|
Subroutine
is_true: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 3 | my ($self, $code, @args) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | $code ||= $self->can('value') ? 'value' : sub{}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Branch: 1 branch
Condition33%1/3
$code ||= $self->can("value") ? "value" : sub {
}
MC/DC0%0/2
$code ||= $self->can("value") ? "value" : sub {
}
$code
$self->can("value") ? "value" : sub {
}
Truth table33%1/3
A ||= B
A= $codeB= $self->can("value") ? "value" : sub {
}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | require Venus::Boolean; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | ▶ | return $self->$code(@args) ? Venus::Boolean::TRUE() : Venus::Boolean::FALSE(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # EXPORTS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 120 | ▶ | sub EXPORT { | ||||||||||||||||||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 120 | ['is_false', 'is_true'] | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 119 | 1; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 NAME | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Venus::Role::Testable - Testable Role | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Testable Role for Perl 5 | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | package Example; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | use Venus::Class; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | with 'Venus::Role::Testable'; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | attr 'value'; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub execute { | ||||||||||||||||||||||||||||
| 67 | return pop; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | package main; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # $example->is_true(sub{0}); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | This package modifies the consuming package and provides methods for | ||||||||||||||||||||||||||||
| 81 | dispatching method calls and returning truthy returns as true and falsy returns | ||||||||||||||||||||||||||||
| 82 | as false boolean values. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 METHODS | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 is_false | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | is_false(string | coderef $method, any @args) (boolean) | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | The is_false method dispatches the method call or executes the callback and | ||||||||||||||||||||||||||||
| 97 | returns truthy as C<false> and falsy returns as C<true> | ||||||||||||||||||||||||||||
| 98 | L<"boolean"|Venus::Boolean> values. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =over 4 | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =item is_false example 1 | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | package main; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | my $true = $example->is_false(execute => 0); | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # 1 | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =back | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =over 4 | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item is_false example 2 | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | package main; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | my $true = $example->is_false(sub{0}); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # 1 | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =back | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =over 4 | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item is_false example 3 | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | package main; | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | my $false = $example->is_false(execute => 1); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # 0 | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =back | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 is_true | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | is_true(string | coderef $method, any @args) (boolean) | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | The is_true method dispatches the method call or executes the callback and | ||||||||||||||||||||||||||||
| 151 | returns truthy returns as C<true> and falsy returns as C<false> | ||||||||||||||||||||||||||||
| 152 | L<"boolean"|Venus::Boolean> values. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =over 4 | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =item is_true example 1 | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | package main; | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | my $true = $example->is_true(execute => 1); | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # 1 | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =back | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =over 4 | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =item is_true example 2 | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | package main; | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | my $true = $example->is_true(sub{1}); | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # 1 | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =back | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =over 4 | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item is_true example 3 | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | package main; | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | my $false = $example->is_true(execute => 0); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # 0 | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =back | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =cut | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 211 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||