Hoppy::TCPHandler::Input - TCP handler class that will be used when client input any data.


Hoppy documentation Contained in the Hoppy distribution.

Index


Code Index:

NAME

Top

Hoppy::TCPHandler::Input - TCP handler class that will be used when client input any data.

SYNOPSIS

Top

DESCRIPTION

Top

TCP handler class that will be used when client input any data. And then, it dispatches input data to registered classes.

METHODS

Top

do_handle($poe)

cross_domain_policy_xml

AUTHOR

Top

Takeshi Miki <miki@cpan.org>

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top


Hoppy documentation Contained in the Hoppy distribution.

package Hoppy::TCPHandler::Input;
use strict;
use warnings;
use base qw( Hoppy::Base );

sub do_handle {
    my $self  = shift;
    my $poe   = shift;
    my $c     = $self->context;
    my $input = $poe->args->[0];

    if ( $input =~ /policy-file-request/ ) {
        my $xml = $self->cross_domain_policy_xml;
        $c->handler->{Send}->do_handle( $poe, $xml );
    }
    elsif ( $input =~ /^exit(\x00)*/ ) {
        $c->handler->{Disconnected}->do_handle($poe);
    }
    else {
        my $in_data = '';
        eval { $in_data = $c->formatter->deserialize($input); };
        if ($@) {
            warn "IO Format Error: $@";
        }
        else {
            $c->dispatch( $in_data, $poe );
        }
    }

    if ( my $hook = $c->hook->{client_input} ) {
        $hook->work( { poe => $poe } );
    }
}

sub cross_domain_policy_xml {
    my $self = shift;
    my $xml  = <<"    END";
        <?xml version="1.0"?>
        <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
        <cross-domain-policy>
        <allow-access-from domain="*" to-ports="*" />
        </cross-domain-policy>
    END
    return $xml;
}

1;
__END__