[Catalyst] TT2 + CP::Authentication + DBIC gotcha

Christopher Heschong chris at wiw.org
Fri Jul 13 20:08:51 GMT 2007


> On Fri, Jul 13, 2007 at 05:31:53PM +0100, Matt Lawrence wrote:
>> stephen joseph butler wrote:
>> >On 7/13/07, Matt Lawrence <matt.lawrence at ymogen.net> wrote:
>> >>Perrin Harkins wrote:
>> >>> my $vote = $foo if ($bar);  # <--- bad!
>> >>>
>> >>What's wrong with that? I find it a lot more readable than
>> >>
>> >>my $vote;
>> >>if ($bar) {
>> >>    $vote = $foo;
>> >>}
>> >
>> >It doesn't work this way, but suppose you wrote this:
>> >
>> >if ($bar) {
>> > my $vote = $foo
>> >}
>> >
>> >Now see why it's wrong? The way you wrote it is kind of ambiguous for
>> >the way we think of postfix operators. If you want something one line,
>> >how about this:
>> >
>> >my $vote = $foo ? $bar : undef;
>>
>> I can't replicate this behaviour. As far as I can tell, the postfix if
>> is identical to the block if I wrote above.
>>
>>
>> perl -Mstrict -wle 'my $foo = 1 if 0; print defined $foo ? $foo :
>> "undef"'
>> undef
>>
>>
>> Has the bug been fixed?
>
> No, because people use the "if 0" construct as a way to create a static.
>
> cain$ re.pl
> $ sub foo { my $foo if 0; $foo++; }
> $ foo();
> 0
>      $ foo();
> 1
>      $ foo();
> 2
>      $
>
> However in 5.10 you -will- get a warning using this construct since it
> almost
> always indicates buggy code; the number of people who actually -need- a
> static rather than just a lexically closed-over var is vanishingly small
> and
> they can explicitly turn off the behaviour themselves.

What about:

my $vote = $bar and $foo;

Seems to pass the test above and is vaguely readable.  Is it similarly evil?





More information about the Catalyst mailing list