Data::Result - Handling true and false in a better way!
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"; }
Handling true and false isn't always enough. This alows true and false to encapsulate things as a simple state.
Data::Result provides the following constructor arguments
Required arguments:
is_true: true or fale # if not blessed it will be converted to a boolean true or false object
Optional arguments
data: Data this object contains msg: A human readable string representing this object. extra: another slot to put data in
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);
my $result=Data::Result->new(is_true=>1,msg=>$msg,extra=>$data);
boolean
Mike Shipper <AKALINUX@CPAN.ORG>
To install Data::Result, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Result
CPAN shell
perl -MCPAN -e shell install Data::Result
For more information on module installation, please visit the detailed CPAN module installation guide.