Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Is there an andand for Perl like there is in Ruby?

by ForgotPasswordAgain (Deacon)
on Jan 08, 2009 at 13:13 UTC ( #734880=note: print w/replies, xml ) Need Help??

in reply to Is there an andand for Perl like there is in Ruby?

Another way to think about it might be: why do you have to check that ShopperDueDate is true in the first place?

For example, you could have $shop->ShopperDueDate throw an exception if it's not true that it can('day_name'), then

eval { say $shop->ShopperDueDate->day_name };

Ok, I'm joking, but what about never allowing ->ShopperDueDate to be a non-DateTime object (or whatever). Like in Moose:

package Shop; use Moose; .... has 'ShopperDueDate' => (...., isa => 'DateTime', default => sub { Dat +eTime->new });

Now when $shop is initialized, you know that ShopperDueDate can call day_name, so you just write

say $shop->ShopperDueDate->day_name;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://734880]
[erix]: ( postgres has adopted TAP tests + perl for testing, and I'm playing around with that )
[Corion]: erix: Maybe the program re-opens STDERR or something like that? Also, I think you need to redirect first and then do the 2>&1 thing, but I never know and have to Google that
[huck]: erix some things also write to the raw console/tty/pty rather than stdout/stderr
[Discipulus]: see this useful site
[erix]: hm. ok. Either might be the case here. I guess I need to try out more
[choroba]: The redirections seem to happen right to left

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-03-23 08:15 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (284 votes). Check out past polls.