Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Controller: Added before_pause and after_pause

  • Loading branch information...
commit bc304a09595fb4fbfd978f1c7c322d742134e649 1 parent 975d2a5
@Blaizer Blaizer authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 lib/SDLx/Controller.pm
View
24 lib/SDLx/Controller.pm
@@ -24,6 +24,8 @@ my %_delay;
my %_paused;
my %_time;
my %_stop_handler;
+my %_before_pause;
+my %_after_pause;
use constant {
STOP => '1',
@@ -54,6 +56,8 @@ sub new {
# $_paused{ $ref } = undef;
$_time{ $ref } = $args{time} || 0;
$_stop_handler{ $ref } = exists $args{stop_handler} ? $args{stop_handler} : \&default_stop_handler;
+ $_before_pause{ $ref } = $args{before_pause};
+ $_after_pause{ $ref } = $args{after_pause};
return $self;
}
@@ -74,6 +78,8 @@ sub DESTROY {
delete $_paused{ $ref };
delete $_time{ $ref };
delete $_stop_handler{ $ref };
+ delete $_before_pause{ $ref };
+ delete $_after_pause{ $ref };
}
sub run {
@@ -133,7 +139,9 @@ sub run {
# pause works by stopping the app and running it again
if( $_paused{ $ref } ) {
+ $_before_pause{ $ref }->($self) if $_before_pause{ $ref };
$self->_pause($ref);
+ $_after_pause{ $ref }->($self) if $_after_pause{ $ref };
# exit out of this sub before going back in so we don't recurse deeper and deeper
goto $self->can('run')
@@ -344,6 +352,22 @@ sub stop_handler {
$_stop_handler{ $ref };
}
+sub before_pause {
+ my ($self, $arg) = @_;
+ my $ref = refaddr $self;
+ $_before_pause{ $ref } = $arg if @_ > 1;
+
+ $_before_pause{ $ref };
+}
+
+sub after_pause {
+ my ($self, $arg) = @_;
+ my $ref = refaddr $self;
+ $_after_pause{ $ref } = $arg if @_ > 1;
+
+ $_after_pause{ $ref };
+}
+
sub default_stop_handler {
my ($event, $self) = @_;

0 comments on commit bc304a0

Please sign in to comment.
Something went wrong with that request. Please try again.