Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] Why autodie?

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Marc Chantreux <address@concealed>
  • To: "Stefan Hornburg (Racke)" <address@concealed>
  • Cc: address@concealed
  • Subject: Re: [sympa-developpers] Why autodie?
  • Date: Thu, 22 Feb 2018 11:17:12 +0100

hello Racke,

> > $list += $subscriber
> > instead of
> > $list->add_subscriber( $subscriber )
> My impression is that we can do that in Perl with operator overloading.

perl can but should we? it seems David isn't fan of the idea.

> I like talks, but docs are faster and also easier to find.

that's why si doc is coming too.

> So as a typical use case when I open a file and it doesn't exist with
> autodie?

> if (open (...)) {
> found ... proceed
> } elsif ( "File not found" ) {
> sure, we look elsewhere
> } else {
> log the error and handle the problem
> }

> Actually a better version would be with try and catch - but how does autodie
> handle that?

i tested it in this file (this is poor testing)

https://github.com/sympa-community/p5-sympatic/blob/master/t/11_use_autodie.t

when $! is rised, $@ is set so if we include Try::Tiny in Sympatic, we
should be able to write

my $fh =
try { open ... }
catch {
# deal with $ERRNO
}

another option is

my $fh
{ no autodie;
...
}

but again: autodie is about raising exceptions when didn't and provide a
decent default (as use strict, use warnings).

regards
marc



Archive powered by MHonArc 2.6.19+.

Top of Page