Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Control Flow - Multiple returns or nested conditionals

by BrowserUk (Patriarch)
on Oct 07, 2010 at 16:20 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found