| 1 | # Declare our package | ||
| 2 | package POE::Component::Lightspeed::Hack::Session; | ||
| 3 | |||
| 4 | # Standard stuff to catch errors | ||
| 5 | use strict qw(subs vars refs); # Make sure we can't mess up | ||
| 6 | use warnings FATAL => 'all'; # Enable warnings to catch errors | ||
| 7 | |||
| 8 | # Initialize our version | ||
| 9 | our $VERSION = '1.' . sprintf( "%04d", (qw($Revision: 1082 $))[1] ); | ||
| 10 | |||
| 11 | # Import the constants | ||
| 12 | use POE::Component::Lightspeed::Constants qw( FROM_KERNEL FROM_SESSION FROM_STATE FROM_FILE FROM_LINE ); | ||
| 13 | |||
| 14 | # Fool programs even more based on our inheritance | ||
| 15 | use base qw( POE::Session ); | ||
| 16 | |||
| 17 | # Create a new instance of ourself | ||
| 18 | sub new { | ||
| 19 | # Get rid of the package name | ||
| 20 | shift; | ||
| 21 | |||
| 22 | # Create ourself | ||
| 23 | my $self = [ @_ ]; | ||
| 24 | |||
| 25 | # Holy blessing... | ||
| 26 | bless $self, 'POE::Component::Lightspeed::Hack::Session'; | ||
| 27 | |||
| 28 | # All done! | ||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | # Accessors | ||
| 33 | sub remote_kernel { | ||
| 34 | return $_[0]->[ FROM_KERNEL ]; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub remote_session { | ||
| 38 | return $_[0]->[ FROM_SESSION ]; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub remote_state { | ||
| 42 | return $_[0]->[ FROM_STATE ]; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub remote_file { | ||
| 46 | return $_[0]->[ FROM_FILE ]; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub remote_line { | ||
| 50 | return $_[0]->[ FROM_LINE ]; | ||
| 51 | } | ||
| 52 | |||
| 53 | # The venerable ID method | ||
| 54 | sub ID { | ||
| 55 | return 'poe://' . $_[0]->[ FROM_KERNEL ] . '/' . $_[0]->[ FROM_SESSION ] . '/'; | ||
| 56 | } | ||
| 57 | |||
| 58 | # Are we a lightspeed session? | ||
| 59 | sub is_lightspeed { | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | |||
| 63 | # Somebody wants us to do something! | ||
| 64 | sub _invoke_state { | ||
| 65 | my( $self, $source_session, $state, $etc, $file, $line, $fromstate ) = @_; | ||
| 66 | |||
| 67 | # What state is this? | ||
| 68 | if ( POE::Component::Lightspeed::Router::DEBUG ) { | ||
| 69 | Carp::confess "_invoke_state called on fake session, which should never happen - state $state"; | ||
| 70 | } | ||
| 71 | |||
| 72 | # Blearh! | ||
| 73 | return undef; | ||
| 74 | } | ||
| 75 | |||
| 76 | # The postback code | ||
| 77 | sub postback { | ||
| 78 | my( $self, $event, @args ) = @_; | ||
| 79 | |||
| 80 | my $postback = sub { | ||
| 81 | $POE::Kernel::poe_kernel->post( | ||
| 82 | $POE::Component::Lightspeed::Router::SES_ALIAS, | ||
| 83 | 'post', | ||
| 84 | [ $self->[ FROM_KERNEL ], $self->[ FROM_SESSION ], $event ], | ||
| 85 | [ [ @args ], [ @_ ] ], | ||
| 86 | ); | ||
| 87 | return 1; | ||
| 88 | }; | ||
| 89 | return $postback; | ||
| 90 | } | ||
| 91 | |||
| 92 | # The callback code | ||
| 93 | sub callback { | ||
| 94 | my( $self, $event, @args ) = @_; | ||
| 95 | |||
| 96 | my $callback = sub { | ||
| 97 | $POE::Kernel::poe_kernel->post( | ||
| 98 | $POE::Component::Lightspeed::Router::SES_ALIAS, | ||
| 99 | 'post', | ||
| 100 | [ $self->[ FROM_KERNEL ], $self->[ FROM_SESSION ], $event ], | ||
| 101 | [ [ @args ], [ @_ ] ], | ||
| 102 | ); | ||
| 103 | return undef; | ||
| 104 | }; | ||
| 105 | return $callback; | ||
| 106 | } | ||
| 107 | |||
| 108 | # Fake up some other subs | ||
| 109 | sub register_state { | ||
| 110 | return undef; | ||
| 111 | } | ||
| 112 | sub option { | ||
| 113 | return undef; | ||
| 114 | } | ||
| 115 | sub get_heap { | ||
| 116 | return undef; | ||
| 117 | } | ||
| 118 | |||
| 119 | # Add some methods to POE::Session | ||
| 120 | package POE::Session; | ||
| 121 | |||
| 122 | sub is_lightspeed { | ||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | |||
| 126 | # End of module | ||
| 127 | 1; | ||
| 128 | __END__ |