[Catalyst-dev] Re: RFC: DWIM redirects

A. Pagaltzis pagaltzis at gmx.de
Sat Jan 6 19:11:25 GMT 2007


* Jonathan Rockway <jon at jrock.us> [2007-01-06 19:25]:
> # here we set the status to something sane.
> # * if it was passed to us, use that
> # * if $self->status is already a redirect (between 300 and
> #   400), then leave it
> # * otherwise set it to 302
> if(!defined $status){
>     if($self->status >= 300 && $self->status < 400){
>         $status = $self->status; # preserve pre-set status             
>     }
>     else {
>         $status = 302; # default
>     }
> }
> 
> $self->location($location);
> $self->status($status);

Ick! Nested ifs and status variables. Had to read it thrice to be
certain of the logic. No wonder you felt the need for a huge
comment block.

    if( defined $status ) {
        $self->status( $status );
    }
    elsif( $self->status < 300 or $self->status >= 400 ) {
        # wasn't a redirect (3xx), so force default
        $self->status( 302 );
    }

    $self->location( $location );

Now *that* I can read while skimming without even slowing down.

-- 
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hacker;
#Aristotle



More information about the Catalyst-dev mailing list