cvsuser     02/05/20 12:46:04

  Added:       P5EEx/Blue/P5EEx/Blue/Widget StateMachine.pm
  Log:
  new file
  
  Revision  Changes    Path
  1.1                  p5ee/P5EEx/Blue/P5EEx/Blue/Widget/StateMachine.pm
  
  Index: StateMachine.pm
  ===================================================================
  
  ######################################################################
  ## $Id: StateMachine.pm,v 1.1 2002/05/20 19:46:04 spadkins Exp $
  ######################################################################
  
  package P5EEx::Blue::Widget::StateMachine;
  $VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  
  use P5EEx::Blue::Widget;
  @ISA = ( "P5EEx::Blue::Widget" );
  
  use strict;
  
  =head1 NAME
  
  P5EEx::Blue::Widget::StateMachine - a simple state machine
  
  =head1 SYNOPSIS
  
     use P5EEx::Blue::Widget::StateMachine;
  
  =cut
  
  #############################################################################
  # PUBLIC METHODS
  #############################################################################
  
  =head1 Public Methods:
  
  =cut
  
  #############################################################################
  # handle_event()
  #############################################################################
  
  =head2 handle_event()
  
  The handle_event() method is called from within the standard Service
  constructor.
  Common to all Widget initializations, is the absorption of container
  attributes.  "Absorbable attributes" from the widget are copied from
  the container widget to the initialized widget.
  
      * Signature: $handled = handle_event($sender_wname,$event,@args)
      * Param:     $sender_wname  string   [in]
      * Param:     $event         string   [in]
      * Param:     @args          any      [in]
      * Return:    $handled       boolean
      * Throws:    P5EEx::Blue::Exception
      * Since:     0.01
  
      Sample Usage: 
  
      $handled = $w->handle_event($sender_wname,$event,@args);
  
  =cut
  
  sub handle_event {
      my ($self, $wname, $event, @args) = @_;
      my ($context, $name, $state, $handled);
  
      $name    = $self->{name};
      $context = $self->{context};
      $state   = $self->get_value();
      $handled = 0;   # assume this event could not be handled
  
      my ($transition, $transitions);
      $transitions = $self->{state}{$state};
      if (defined $transitions) {
          $transition = $transitions->{"$wname-$event"};
          $transition = $transitions->{$event} if (!defined $transition);
          $transition = $transitions->{$wname} if (!defined $transition);
          if ($transition) {
              if ($transition->{state}) {
                  $state = $transition->{state};
                  $self->set_value($state);
              }
              if ($self->{saveArgs}) {
                  my ($var, $value);
                  while ($#args >= 1) {
                      $var   = shift(@args);
                      $value = shift(@args);
                      $self->set($var,$value);
                  }
                  elsif ($self->{args}) {
                      $self->delete("args");
                  }
              }
              if ($self->{saveRawArgs}) {
                  if ($#args > -1) {
                      $self->set("args",\@args);
                  }
                  elsif ($self->{args}) {
                      $self->delete("args");
                  }
              }
              $handled = 1;
          }
      }
  
      if ($handled) {
          return 1;
      }
      else { # try the superclass
          return $self->SUPER::handle_event($wname, $event, @args);
      }
  }
  
  1;
  
  
  
  


Reply via email to