in reply to Re: (jeffa) Re: style for returning errors from subroutines
in thread style for returning errors from subroutines
Also, I really should have included this method below in the Error class. I think it's name explains it's function well enough:package Users; use strict; sub new { my ($class,$error) = @_; my $self = { ERRORS => $error, # and maybe even more . . . $fh? }; bless $self, $class; return $self; } sub get_users { my ($self,$fh) = shift; # rest of your sub # oops, an error happened $self->{ERRORS}->add_error('oops','i like vb'); } # rest of your Users module package main; use strict; use Users; use Error; my $ERROR = Error->new(); my $user = Users->new($ERROR); $user->foo(); print $ERROR->generate_errors(); # or maybe even my @stuff = $user->foo() or print $ERROR->generate_errors();
My original requirements didn't warrant the need for that method, but yours just might.package Error; sub clear { my ($self) = @_; $self->{ERRORS} = undef; } # rest of Error module
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
|
|---|