Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Control Flow - Multiple returns or nested conditionals

by BrowserUk (Pope)
on Oct 07, 2010 at 16:20 UTC ( #864031=note: print w/replies, xml ) Need Help??


in reply to Control Flow - Multiple returns or nested conditionals

Assuming the first example is the correct one as far as the status value goes, I'd code it this way.

Update:tweaked it a bit.

sub bar { my($self) = @_; my $rv = { status => 0, error => undef, external_id => undef }; $rv->{ error } = "Authentication Failed" and return $rv unless $self->authenticate_user(); my $profile = $self->get_user_profile(); $rv->{ error } = "User is not active" and return $rv unless $profile->is_active(); $rv->{ external_id } = $self->find_external_id( $profile ) // $self->send_profile_to_partner( $profile ); $rv->{ status } = 1; return $rv; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864031]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-07-28 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?