Changeset 2924
- Timestamp:
- 08/21/10 22:56:15 (18 months ago)
- Location:
- Catalyst-Plugin-Alarm/trunk
- Files:
-
- 1 added
- 8 edited
-
Alarm.pm (modified) (14 diffs)
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
Makefile.PL (modified) (1 diff)
-
README (modified) (2 diffs)
-
t/00-load.t (modified) (1 diff)
-
t/01-alarm.t (modified) (1 diff)
-
t/02-native-signals.t (added)
-
t/TestApp.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
Catalyst-Plugin-Alarm/trunk/Alarm.pm
r2920 r2924 15 15 # Sys::SigAction doesn't help on Win32 systems 16 16 # because Win32 doesn't use POSIX signals 17 our $WIN32 = 1; 18 unless ( $^O eq 'MSWin32' ) { 19 require Sys::SigAction; 20 $WIN32 = 0; 17 our $USE_NATIVE_SIGNALS = 0; 18 if ( $^O eq 'MSWin32' ) { 19 $USE_NATIVE_SIGNALS = 1; 21 20 } 22 21 … … 32 31 } 33 32 33 sub setup_finalize { 34 my $c = shift; 35 my $ret = $c->next::method(@_); 36 37 my %conf = %{ $c->config->{alarm} }; 38 39 if ( $conf{use_native_signals} ) { 40 $USE_NATIVE_SIGNALS = 1; 41 } 42 else { 43 require Sys::SigAction; # defer till runtime 44 } 45 46 return $ret; 47 } 48 49 # must call on every request 34 50 sub prepare { 35 51 my $class = shift; … … 105 121 }; 106 122 107 if ($ WIN32) {123 if ($USE_NATIVE_SIGNALS) { 108 124 $SIG{ALRM} = $alarm_handler; 109 125 } … … 239 255 eval { 240 256 my $h = $SIG{ALRM}; 241 if ($ WIN32) {257 if ($USE_NATIVE_SIGNALS) { 242 258 $SIG{ALRM} = $alarm_handler; 243 259 } … … 288 304 CORE::alarm($prev_alarm); 289 305 290 if ($ WIN32) {306 if ($USE_NATIVE_SIGNALS) { 291 307 $SIG{ALRM} = $h; 292 308 } … … 352 368 package MyApp; 353 369 use Catalyst qw( Alarm ); 354 MyApp->config ->{alarm} ={370 MyApp->config( alarm => { 355 371 timeout => 60, 356 372 global => 120, 357 373 handler => sub { # do something if alarm sounds } 358 };374 }); 359 375 360 sub default : Private 361 { 376 sub default : Private { 362 377 my ($self,$c) = @_; 363 unless( $c->timeout('foo') ) 364 { 378 unless( $c->timeout('foo') ) { 365 379 $c->stash->{error} = "Sorry to keep you waiting. There was a problem."; 366 380 return; … … 368 382 } 369 383 370 sub foo : Private 371 { 384 sub foo : Private { 372 385 my ($self,$c) = @_; 373 386 sleep 61; … … 443 456 __PACKAGE__->config( alarm => { 444 457 handler => sub { 445 if (ref $_[1]) 446 { 458 if (ref $_[1]) { 447 459 $_[0]->log->error(" .... local alarm went off!!"); 448 460 $_[1]->[0] = 'some return value'; 449 461 $_[0]->alarm->on(0); # turn 'off' the alarm flag 450 462 } 451 else 452 { 463 else { 453 464 $_[0]->log->error(" .... global alarm went off"); 454 465 $_[0]->alarm->on(1); … … 466 477 Example: 467 478 468 __PACKAGE__->config( alarm => {469 override => {470 re=> qr{/ajax/},471 timeout=> 3472 }473 });479 __PACKAGE__->config( alarm => { 480 override => { 481 re=> qr{/ajax/}, 482 timeout=> 3 483 } 484 }); 474 485 475 486 Will set the global timeout value to 3 if the request->path matches C</ajax>. … … 486 497 forward => 1, 487 498 timeout => 10 488 });499 }); 489 500 490 501 Will automatically call timeout() with a default value of 10 seconds, wherever your … … 494 505 feature. 495 506 507 =item use_native_signals 508 509 Default value is false. If set to a true value, Sys::SigAction will not be used 510 and instead the built-in %SIG handlers will be used. This is necessary for the plugin 511 to work under Win32 systems and in some cases with FCGI. 496 512 497 513 =back … … 536 552 537 553 554 =head2 setup_finalize 555 556 Overridden internally. 557 538 558 =head2 prepare 539 559 … … 565 585 566 586 __PACKAGE__->config( alarm => { 567 override => {568 re => qr{/foo/},569 timeout => 3570 }571 });572 sub foo : Global573 {587 override => { 588 re => qr{/foo/}, 589 timeout => 3 590 } 591 }); 592 593 sub foo : Global { 574 594 my ($self,$c) = @_; 575 595 $c->alarm->off; # negates the override in config … … 655 675 for more details. 656 676 657 Win32 systems don't have alarm() or other signal handlers. That's not really the fault 658 of this module, but listed here in case you try using this on a Win32 system and it balks. 659 You might try setting the PERL_SIGNALS environment variable to C<unsafe> but that wouldn't 660 be very safe, now would it? 677 Win32 systems don't have alarm() or other signal handlers, so B<use_native_signals> 678 gets turned on if running under Win32. 679 680 Some users report that Sys::SigAction does not play nicely with FCGI, 681 so you can set the B<use_native_signals> to a true value to use the built-in 682 %SIG handlers instead of Sys::SigAction. 661 683 662 684 =head1 AUTHOR -
Catalyst-Plugin-Alarm/trunk/Changes
r1977 r2924 14 14 instead of NEXT. 15 15 16 16 0.05 21 Aug 2010 17 - add 'use_native_signals' config option to avoid dependency 18 on Sys::SigAction (see https://rt.cpan.org/Ticket/Display.html?id=60566) -
Catalyst-Plugin-Alarm/trunk/MANIFEST
r2921 r2924 5 5 t/00-load.t 6 6 t/01-alarm.t 7 t/02-native-signals.t 7 8 t/TestApp/Controller/Root.pm 8 9 t/TestApp.pm -
Catalyst-Plugin-Alarm/trunk/Makefile.PL
r1977 r2924 4 4 5 5 WriteMakefile( 6 NAME => 'Catalyst::Plugin::Alarm',7 VERSION_FROM => 'Alarm.pm',8 PREREQ_PM => {9 'Sys::SigAction' => 0.04,10 'Time::HiRes'=> 1.0,11 'Class::Accessor::Fast' => 0,12 'Catalyst::Runtime' => 5.7,13 'MRO::Compat'=> 0,6 NAME => 'Catalyst::Plugin::Alarm', 7 VERSION_FROM => 'Alarm.pm', 8 PREREQ_PM => { 9 'Sys::SigAction' => 0.11, 10 'Time::HiRes' => 1.0, 11 'Class::Accessor::Fast' => 0, 12 'Catalyst::Runtime' => 5.8, 13 'MRO::Compat' => 0, 14 14 15 },16 AUTHOR => 'Peter Karman <pkarman@atomiclearning.com>',17 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },18 clean => { FILES => 'Catalyst-Plugin-Alarm-*' },15 }, 16 AUTHOR => 'Peter Karman <karman@cpan.org>', 17 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 18 clean => { FILES => 'Catalyst-Plugin-Alarm-*' }, 19 19 20 20 ); -
Catalyst-Plugin-Alarm/trunk/README
r898 r2924 1 Catalyst::Plugin::Alarm version 0.011 Catalyst::Plugin::Alarm 2 2 ================ 3 3 4 Implements Sys::SigActionalarms with Time::HiRes for Catalyst.4 Implements alarms with Time::HiRes for Catalyst. 5 5 6 6 INSTALLATION … … 17 17 This module requires these other modules and libraries: 18 18 19 Sys::SigAction 19 Sys::SigAction (optional) 20 20 Time::HiRes 21 21 -
Catalyst-Plugin-Alarm/trunk/t/00-load.t
r898 r2924 1 1 use Test::More tests => 1; 2 BEGIN { use_ok('Alarm') } ;2 BEGIN { use_ok('Alarm') } 3 3 4 diag( "Testing Catalyst::Plugin::Alarm $Catalyst::Plugin::Alarm::VERSION" ); 5 diag( "Testing Sys::SigAction $Sys::SigAction::VERSION" ); 4 diag("Testing Catalyst::Plugin::Alarm $Catalyst::Plugin::Alarm::VERSION"); 6 5 6 eval { 7 require Sys::SigAction; 8 diag("Testing Sys::SigAction $Sys::SigAction::VERSION"); 9 }; -
Catalyst-Plugin-Alarm/trunk/t/01-alarm.t
r2920 r2924 3 3 use Catalyst::Test 'TestApp'; 4 4 use Test::More tests => 7; 5 6 diag("USE_NATIVE_SIGNALS = $Catalyst::Plugin::Alarm::USE_NATIVE_SIGNALS"); 5 7 6 8 # some tests defined in the TestApp files -
Catalyst-Plugin-Alarm/trunk/t/TestApp.pm
r2920 r2924 20 20 } 21 21 }, 22 global => 5 22 global => 5, 23 use_native_signals => $ENV{USE_NATIVE_SIGNALS}, 23 24 }, 24 25 );
Note: See TracChangeset
for help on using the changeset viewer.