NAME
Data::Result - Handling true and false in a better way!
SYNOPSIS
use Modern::Perl;
use Data::Result;
# just true
my $result=Data::Result->new(is_true=>0);
if($result) {
print "Yup its true!\n";
}
# True with data
$result=Data::Result->new(is_true=>1,data=>'Yup This is true!');
if($result) {
print $result->data,"\n";
}
# just flase
$result=Data::Result->new(is_true=>0);
if($result) {
print $result->data,"\n";
} else {
print "well, something went wrong!\n";
}
# handle false, but give us an error!
$result=Data::Result->new(is_true=>0,msg=>'this is our message');
if($result) {
print $result->data,"\n";
} else {
print "$result\n";
}
DESCRIPTION
Handling true and false isn't always enough. This alows true and false to encapsulate things as a simple state.
Object Constructor Arguments
Data::Result provides the following constructor arguments
Required arguments:
is_true: true or fale
Optional arguments
data: Data this object contains
msg: A human readable string representing this object.
extra: another slot to put data in
OO Methods
my $data=$result->get_data
Simply a wrapper for $result->data
if($result->is_false) { ... }
Inverts $self->is_true
my $result=Data::Result->new_true($data,$extra);
Wrapper for
my $result=Data::Result->new(is_true=>1,data=>$data,extra=>$data);
my $result=Data::Result->new_false($msg,$extra);
Wrapper for
my $result=Data::Result->new(is_true=>1,msg=>$msg,extra=>$data);
AUTHOR
Mike Shipper <AKALINUX@CPAN.ORG>