Changeset 34681 for lang/perl

Show
Ignore:
Timestamp:
07/31/09 09:37:29 (5 years ago)
Author:
ktat
Message:

add beep

Location:
lang/perl/Script-Carp/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Script-Carp/trunk/Changes

    r33935 r34681  
    11Revision history for Script-Carp 
     2 
     30.04    2009-07-31 09:35:00 
     4        add beep. 
    25 
    360.03    2009-06-13 15:12:00 
    47        fix test script. 
     8        add log. 
    59 
    6100.02    2009-06-08 14:37:59 
  • lang/perl/Script-Carp/trunk/lib/Script/Carp.pm

    r33935 r34681  
    1313  if (defined $_[0] and $_[0] =~/^Died /) { 
    1414    $_die->(@_) 
     15  } elsif (defined $_[0] and $_[0] =~/ at $filename line $line\./)  { 
     16    $_die->('Died ', @_); 
    1517  } else { 
    1618    $_die->('Died ', @_, " at $filename line $line.\n") 
     
    4749       close $out; 
    4850     }; 
     51   }, 
     52   -beep => sub { 
     53     local $@; 
     54     eval "require Audio::Beep"; 
     55     unless ($@) { 
     56       my ($args) = @_; 
     57       $args->[0] ||= "g'"; 
     58       my $beep = $args->[0] =~/^-/ ? "c' d' e'" : shift @$args; 
     59       return sub { 
     60         Audio::Beep->new->play($beep); 
     61       } 
     62     } else { 
     63       my $msg = "You need Audio::Beep module."; 
     64       $msg .= ' you may need "modprobe pcspkr" and/or "xset b on"' if $^O =~/linux/i; 
     65       warn $msg; 
     66       return sub {}; 
     67     } 
    4968   }, 
    5069   -ignore_eval => sub { 
     
    99118=cut 
    100119 
    101 our $VERSION = '0.03'; 
     120our $VERSION = '0.04'; 
    102121 
    103122 
     
    108127  use Script::Carp -stop; # display error and wait STDIN 
    109128  use Script::Carp -file => "error.txt"; # write message to error.txt 
     129  use Script::Carp -stop, -file => "error.txt"; # mixed the above 
    110130  use Script::Carp -log  => "error_log.txt"; # append message to error_log.txt 
    111   use Script::Carp -stop, -file => "error.txt"; # mixed the above 
     131  use Script::Carp -beep => "c d e f g"; # beep 
     132 
    112133 
    113134use class method with options 
     
    117138  Script::Carp->setup(-log => "error_log.txt"); 
    118139  Script::Carp->setup(-stop, -file => "error.txt"); 
     140  Script::Carp->setup(-beep => "c d e f g"); 
    119141 
    120142=head1 DESCRIPTION 
     
    163185It is like file, but it will not clear file content. 
    164186When script died, messages are appended to "log_file_name". 
     187 
     188=head2 -beep 
     189 
     190 use Script::Carp -beep; 
     191 use Script::Carp -beep => "c d e f g"; 
     192 
     193or 
     194 
     195 Script::Carp->setup(-beep); 
     196 Script::Carp->setup(-beep => "c d e f g"); 
     197 
     198beep when died. It requires Audio::Beep module. 
     199If you use Linux, you may need to 'modprobe pcspkr", 'xset -b on' 
    165200 
    166201=head1 METHOD