[Moscow.pm] perl

Nikolay Mishin mi ya.ru
28 14:51:52 PDT 2013


, ,   Try::Tiny ,
 2 
 eval
https://github.com/mishin/gists/blob/master/test_ff1.pl
c Try::Tiny
https://github.com/mishin/gists/blob/master/test_ff1_try.pl
  ,
  
 5.18 perlcritic -5   
Error.pm 
     error class   ,
    -  
  ?

29.10.2013, 01:10, " " <asan999  gmail.com>:
> $ERRNO  $!,   $@,   Try::Tiny  $_ :
>
> perl -MCarp -MTry::Tiny -E 'try { croak "aaaaa" } catch { say "XXX: $_" }'
>
>    
>
> 29.10.2013 0:04, Nikolay Mishin :
>
>> MoscowPM, ,
>>     ;))
>>
>>   ,    firefox,   ,  (https://github.com/mishin/gists/blob/master/trans.pl
>> 100-133)
>>
>>  my $url = 'http://www.translate.ru/';
>>  my $firemech;
>>
>>  my $lived = eval {
>>  $firemech = WWW::Mechanize::Firefox->new( tab => qr/PROMT/sm, );
>>  1;
>>  };
>>  my $err = $ERRNO; # $@;
>>
>>  given ($err) {
>>
>> #Failed to connect to , problem connecting to "localhost", port 4242: Connection refused at /usr/local/share/perl/5.14.2/MozRepl/Client.pm line 144
>>  when (/\QFailed to connect to , problem connecting to\E/xsm) {
>>
>>  # use Test::More;
>>  # is $lived, undef, 'We died trying to connect to a non-existing tab';
>>  # like $err, q{/Couldn't find a tab matching/},
>>  # 'We got the correct error message';
>>  my $path_to_firefox =
>>  os_is('MSWin32')
>>  ? 'C:/Program Files (x86)/Mozilla Firefox/firefox.exe'
>>  : '/usr/bin/firefox';
>>  $firemech = WWW::Mechanize::Firefox->new(
>>  tab => 'current',
>>  launch => $path_to_firefox
>>  );
>>  $firemech->get($url) or die "Cannot connect to $url\n";
>>  }
>>
>>  #Couldn't find a tab matching /(?^ums:PROMT)/ at trans.pl line 100.
>>  when (/\QCouldn't find a tab matching\E/xsm) {
>>  say 'we match error' . $_;
>>  $firemech = WWW::Mechanize::Firefox->new( tab => 'current', );
>>  $firemech->get($url) or die "Cannot connect to $url\n";
>>  }
>>  }
>>
>>    Try:;Tiny  Error.pm
>>   ,     
>>   ,  
>> Error.pm -     ,   
>>
>>        eval
>>    ,  WWW::Mechanize::Firefox
>> https://metacpan.org/source/CORION/WWW-Mechanize-Firefox-0.74/lib/WWW/Mechanize/Firefox.pm
>>   
>> useCarpqw(carp croak );
>> ,  ,     Try::Tiny
>> -   ,
>>     ,     
>> https://metacpan.org/source/CORION/WWW-Mechanize-Firefox-0.74/t/50-mech-new.t
>>
>>  Try::Tiny   , ,   
>> -  -   Perl Best Practice
>>  ,  
>> --
>>  
>>  
>
> ,
> --
> Moscow.pm mailing list
> moscow-pm  pm.org | http://moscow.pm.org

-- 
 
 



Moscow-pm