AMF-Perl

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension AMF::Perl.

0.15 Sun Sep 19 13:01:35 EDT 2004
Converted examples (except for Petmarket) to ActionScript 2.0 under Flash MX 2004.
Patches from Kostas Chatzikokolakis about error checking of input data length.
WriteUTF() writes the string length as long for lengths > 65535.
Also, check for (defined $s) and not just ($s) in writeUTF.

0.14 Sun Jul 11 18:59:36 EDT 2004
Really fixed the number 16 issue (forgot to include the change in 0.13).
Added Richard Boulton's change to readDouble() and writeDouble() to take into account endian-ness.
Changed the behavior of amf_throw() to enable die() to work.

0.13 Sun Jun 20 15:52:57 EDT 2004
Started duplicating changes in this file.

doc/examples/basic/basic.html  view on Meta::CPAN

This shows various data types passed through AMF to the perl backend and sent back.
The most interesting this is not so much what it does, but how it works. The Perl script utilizes the "service discovery" approach - you simply put Perl modules into a certain directory, and they are automatically registered as services.
<br><br>
This example also shows how to throw exceptions, handled by functionName_onStatus in the Flash client (as opposed to functionName_onResult, which is called normally). Simply include in your Perl code
<pre>
use AMF::Perl qw/amf_throw/;
</pre>

and then call <em>amf_throw()</em> with a string or an arbitrary object as a parameter.
<br><br>
If you call <em>die "Error message"</em>, it will be also caught in the same way and sent as an error to Flash.

<br><br>
<a href=basic.pl>This is the server-side Perl script basic.pl.</a>
<a href=basicservices/DataEcho.pm>This is a sample service DataEcho.pm.</a>
</td>
<td width=600>
&nbsp;&nbsp;&nbsp;
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" id="basic" width=550 height=350>
<PARAM NAME=movie VALUE="basic.swf"> 

doc/examples/basic/basicservices/DataEcho.pm  view on Meta::CPAN


=head1 NAME
    DataEcho
        
==head1 DESCRIPTION    

    Service class used in conjusction with basic.pl
    
    All AMF::Perl service classes must define the method table, where the user can supply optional description and return type.

	If you want to return an error message, handled by functionName_onStatus in the Flash client (as opposed to functionName_onResult, which is normal), include

use AMF::Perl qw/amf_throw/;

and then call amf_throw() with a string or an arbitrary object as a parameter.


==head1 CHANGES

Tue Jul  6 22:06:56 EDT 2004
Added exception throwing via amf_throw().

doc/examples/basic/basicservices/DataEcho.pm  view on Meta::CPAN

            "description" => "Echoes a Flash Date Object (the returnType needs setting)",
            "access" => "remote", # available values are private, public, remote
            "returns" => "date"
        },
        "echoXML" => {
            "description" => "Echoes a Flash XML Object (the returnType needs setting)",
            "access" => "remote", # available values are private, public, remote
            "returns" => "xml"
        },
        "generateError" => {
            "description" => "Throw an error so that _status, not _result on the client side is called",
            "access" => "remote", # available values are private, public, remote
        },
    };
}

sub echoNormal
{
    my ($self, $data) = @_;
    return $data;
}

doc/examples/basic/basicservices/DataEcho.pm  view on Meta::CPAN

{
    my ($self, $data) = @_;
    return $data;
}

#This function will NOT return the value, because the call to amf_throw() will interrupt
#the control flow and cause the _Status function on the client to be called.
sub generateError
{
    my ($self, $data) = @_;
    amf_throw("An error!!!");
    return "No error";
}

1;

doc/updates.html  view on Meta::CPAN

<body
 style="background-image: url(orn5.gif);">
<div style="position: absolute; left: 20px;">
<h1>AMF::Perl - Flash Remoting in Perl<br>
</h1>
<table cellpadding="2" cellspacing="2" border="0"
 style="text-align: left; width: 600px;">
  <tbody>
	<tr><td>
      <h2><a href="http://www.simonf.com/amfperl">AMF::Perl</a> update history</h2>
                <br><br>September 19, 2004. Version 0.15 uploaded. Converted examples to ActionScript 2.0, better input error checking.

                <br><br>Jul 11, 2004. Version 0.14 uploaded. Endianness, better exception handling.
                        
		<br><br>Jul 06, 2004. Version 0.13 uploaded. Small bug fixes, exception handling.

		<br><br>Apr 29, 2004. Version 0.12 uploaded. Changed "use Apache2" to "require Apache2".

		<br><br>Apr 24, 2004. Flash::FLAP renamed to AMF::Perl. Version 0.11 uploaded (0.10 was an interim release). Hopefully complete mod_perl 1 and 2 handling. Mysql column type determination.

		<br><br>Mar 13, 2004. Version 0.09 uploaded. Fixed a couple of "uninitialized" warnings, accepted patches for POD documentation, smarter detection of numbers and dates in Serializer and text encoding.

lib/AMF/Perl.pm  view on Meta::CPAN

        eval
        {
           $results =  $self->{exec}->doMethodCall( $body->{"value"} );
           # get the return type
           $returnType = $self->{exec}->getReturnType();
        };

        
        if ( $@ )
        {
            $results = UNIVERSAL::isa( $@, 'AMFException' ) ?  $@->error : constructException($@);
            $self->{"response"} = "/onStatus";
            $returnType = "AMFObject"; 
        } 

        # save the result in our amfout object
        $amfout->addBody($body->{"response"}.$self->{"response"}, "null", $results, $returnType);
    }
    
    # create a new output stream
    my $outstream = new AMF::Perl::IO::OutputStream ();

lib/AMF/Perl.pm  view on Meta::CPAN

    $self->{exec}->registerService($package, $servicepackage);
}


sub constructException
{
    my ($description) = @_;
    my $stack = Devel::StackTrace->new();

    my %result;
    $description = "An error occurred" unless $description;
    $result{"description"} = $description;
    $result{"exceptionStack"} = $stack->as_string;
    my @frames = $stack->frames;
    $result{"details"} = $frames[1]->filename();
    $result{"line"} = $frames[1]->line();
    $result{"level"} = "Error";
    $result{"code"} = "1";
    return \%result;
}


sub amf_throw
{
    my ($description) = @_;

    AMFException->throw( error => constructException($description) );
}


sub setSafeExecution
{
    my ($self, $safe) = @_;
    print STDERR "There is no need to call setSafeExecution anymore!\n";
}

sub encoding

lib/AMF/Perl/App/Executive.pm  view on Meta::CPAN

sub setTarget
{
    my ($self, $target)=@_;
    $self->{target} = $target;
    # grab the position of the last . char
    my $lpos = strrpos($target, ".");
    # there were none
    unless ($lpos) 
    {
        print STDERR "Service name $target does not contain a dot.\n";
        # throw an error because there has to be atleast 1
    } 
    else
    {
        # the method name is the very last part
        $self->{_methodname} = substr($target, $lpos+1);
    }
    # truncate the method name from the string
    my $trunced = substr($target, 0, $lpos);
    
    $self->{_classname} = $trunced;

lib/AMF/Perl/App/Executive.pm  view on Meta::CPAN

        {
# map the _methodname to the alias
            $method = $methodrecord{'alias'};
        }

        if (exists($methodrecord{'instance'}))
        {
# check the instance names to see if they match.  If so, then let this happen
            if (!exists($methodrecord{'instance'}) || $self->{_instanceName} != $methodrecord{'instance'})
            {	
# if they don't match then print STDERR  with this error
            print STDERR  "Access error for " . $self->{_headerFilter} . ".\n";
            return;
            }
        }
        
        # check to see if an explicit return type was defined
        if (exists($methodrecord{'returns'}))
        {
            $self->{_returnType} = $methodrecord{'returns'};
        }
        # set the default return type of "unknown"

lib/AMF/Perl/App/Executive.pm  view on Meta::CPAN

        if ( (exists($methodrecord{'access'})) && (lc ($methodrecord{'access'}) eq "remote"))
        {
            # finally check to see if the method existed
            if ($self->{_classConstruct}->can($method))
            {
                # execute the method and return it's results to the gateway
                return $self->{_classConstruct}->$method(@$a);
            }
            else
            {
                # print STDERR  with error
                print STDERR  "Method " . $calledMethod . " does not exist in class ".$self->{_classConstruct}.".\n";
            }
        }
        else
        {
            # print STDERR  with error
            print STDERR  "Access Denied to " . $calledMethod . "\n";
        }
            
        
    }
    else
    {
        # print STDERR  with error
        print STDERR  "Function " . $calledMethod . " does not exist in class ".$self->{_classConstruct}.".\n";
    }

}

sub doMethodCall_registered
{
    my ($self, $package, $method, $a) = @_;
    
    my $serviceobject = $self->{services}->{$package};

    if(length($package) == 0)
    {
    # TODO: handle non packaged functions
    #trigger_error("ERROR: no package in call",E_USER_ERROR);
        return;
    } 
    elsif(!$serviceobject)
    {
        print STDERR "Package ".$package." not registerd on server\n";
        return;
    } 
    elsif(!$serviceobject->can($method))
    {
        print STDERR "Function ".$method." does not exist in package ".$package."\n";

lib/AMF/Perl/IO/Deserializer.pm  view on Meta::CPAN

AMF::Perl::IO::Deserializer

=head1 DESCRIPTION    

    Package used to turn the binary data into physical perl objects.

=head1 CHANGES

=head2 Sun Sep 19 13:01:35 EDT 2004

=item Patch from Kostas Chatzikokolakis about error checking of input data length.

=head2 Sat Mar 13 16:31:31 EST 2004

=item Patch from Kostas Chatzikokolakis handling encoding.

=head2 Sun Mar  9 18:17:31 EST 2003

=item The return value of readArray should be \@ret, not @ret.

=head2 Tue Mar 11 21:55:41 EST 2003

lib/AMF/Perl/IO/InputStream.pm  view on Meta::CPAN


    AMF::Perl::IO::InputStream

=head1 DESCRIPTION    

    InputStream package built to handle getting the binary data from the raw input stream.

=head1 CHANGES    

=head2 Sun Sep 19 13:01:35 EDT 2004
=item Patch from Kostas Chatzikokolakis about error checking of input data length.

=head2 Tue Jun 22 19:28:30 EDT 2004
=item Improved the check in readDouble to append "0" to the string instead of skipping
the value. Otherwise the number 16 did not go through.
=item Added defined($thisByte) in readInt, otherwise the character "0" (say, in string length of 30)
did not go through.

=head2 Sat Mar 13 16:39:29 EST 2004

=item Changed calls to ord() in readByte() and concatenation readDouble() 

lib/AMF/Perl/IO/Serializer.pm  view on Meta::CPAN


# were still lacking dates, xml, and strings longer than 65536 chars
sub writeData
{
    my ($self, $d, $type)=@_;
    $type = "unknown" unless $type;

#    **************** TO DO **********************
#    Since we are now allowing the user to determine
#    the datatype we have to validate the user's suggestion
#    vs. the actual data being passed and throw an error
#    if things don't check out.!!!!
#    **********************************************

    # get the type of the data by checking its reference name
    #if it was not explicitly passed
    if ($type eq "unknown")
    {
		if (!defined $d)		# convert undef to null, but not "" or 0
		{
			$type = "NULL";



( run in 0.631 second using v1.01-cache-2.11-cpan-65fba6d93b7 )