perl - Is it unpolite to put an END block in a module? -


would ok keep end block in example, because nobody wants broken terminal or shouldn't put end block in module?

package my_package; use warnings; use strict; use term::readkey;  sub _init_scr {     ( $arg ) = @_;     $arg->{backup_flush} = $|;     $| = 1;     term::readkey::readmode 'ultra-raw'; }  sub _end_win {     ( $arg ) = @_;     print "\n\r";     term::readkey::readmode 'restore';     $| = $arg->{backup_flush}; }  end {     term::readkey::readmode 'restore'; }  sub my_function {     $arg = {};     _init_scr( $arg );     while ( 1 ) {         $c = readkey 0;         if ( ! defined $c ) {             _end_win( $arg );             warn "eot";             return;         }         next if $c eq "\e";         given ( $c ) {             when ( $c ge 'a' && $c le 'z' ) {                 print $c;                 $arg->{string} .= $c;             }             when ( $c eq "\cc" ) {                 _end_win( $arg );                 print stderr "^c";                 kill( 'int', $$ );                 return;             }             when ( $c eq "\r" ) {                 _end_win( $arg );                 return $arg->{string};             }         }     } } 

if module changes terminal mode, think polite thing install end block restore terminal mode before program exits.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -