1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
use 5.008;
use strict;
use warnings;
package Sub::HandlesVia::HandlerLibrary::Bool;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.052000';
use Sub::HandlesVia::HandlerLibrary;
our @ISA = 'Sub::HandlesVia::HandlerLibrary';
use Sub::HandlesVia::Handler qw( handler );
our @METHODS = qw( set unset toggle not reset );
sub set {
handler
name => 'Bool:set',
args => 0,
template => '« !!1 »',
documentation => 'Sets the value of the boolean to true.',
_examples => sub {
my ( $class, $attr, $method ) = @_;
return join "",
" my \$object = $class\->new();\n",
" \$object->$method\();\n",
" say \$object->$attr; ## ==> true\n",
"\n";
},
}
sub unset {
handler
name => 'Bool:unset',
args => 0,
template => '« !!0 »',
documentation => 'Sets the value of the boolean to false.',
_examples => sub {
my ( $class, $attr, $method ) = @_;
return join "",
" my \$object = $class\->new();\n",
" \$object->$method\();\n",
" say \$object->$attr; ## ==> false\n",
"\n";
},
}
sub toggle {
handler
name => 'Bool:toggle',
args => 0,
template => '« !$GET »',
documentation => 'Toggles the truth value of the boolean.',
_examples => sub {
my ( $class, $attr, $method ) = @_;
return join "",
" my \$object = $class\->new();\n",
" \$object->$method\();\n",
" say \$object->$attr; ## ==> true\n",
" \$object->$method\();\n",
" say \$object->$attr; ## ==> false\n",
"\n";
},
}
sub not {
handler
name => 'Bool:not',
args => 0,
template => '!$GET',
documentation => 'Returns the opposite value of the boolean.',
_examples => sub {
my ( $class, $attr, $method ) = @_;
return join "",
" my \$object = $class\->new( $attr => 1 );\n",
" say \$object->$method\(); ## ==> false\n",
"\n";
},
}
sub reset {
handler
name => 'Bool:reset',
args => 0,
template => '« $DEFAULT »',
default_for_reset => sub { 0 },
documentation => 'Sets the boolean to its default value, or false if it has no default.',
}
1;
|