AMF-Perl

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

lib/AMF/Perl/IO/Serializer.pm
lib/AMF/Perl/IO/Deserializer.pm
lib/AMF/Perl/Sql/MysqlRecordSet.pm
lib/AMF/Perl/Util/Object.pm
lib/AMF/Perl/Util/RemotingService.pm
Makefile.PL
MANIFEST
README.txt
t/1.t
doc/code.html
doc/encoding.html
doc/cpu.pl
doc/index.html
doc/orn5.gif
doc/examples/README.txt
doc/examples/cpu/cpu.pl
doc/examples/cpu/cpu.fla
doc/examples/cpu/cpu.swf
doc/examples/cpu/cpu.html
doc/examples/dataGrid/dataGrid.pl
doc/examples/dataGrid/dataGrid.swf

doc/code.html  view on Meta::CPAN


This will install the files "NetServices.as" and "NetDebug.as" that are
used in the ActionScript.
      </span></big><br>
      <hr style="width: 100%; height: 2px;"><big><span
 style="font-weight: bold;"></span></big>
      <h2>Sample code that uses Flash Remoting <br>
      </h2>
(See also examples that are distributed with the module).
<br>
<a href=encoding.html>Read this</a> if you want to send and receive strings in non-English encodings.
      <br><br>
Client code:<br>
      <br>
<textarea cols=50 rows=30>
//Obligatory includes
#include "NetServices.as"
#include "NetDebug.as"

//Get a connection object
NetServices.setDefaultGatewayURL("http://host/cpu.pl");

doc/encoding.html  view on Meta::CPAN

<h2>Using non-standard encoding</h2>
Kostas Chatzikokolakis submitted a patch with the following explanation:
<br>
All data in flash remoting are sent as unicode. However, database data
and scripts are usually in a local encoding. I made some enhacements to
AMF::Perl so that it automatically converts all strings to utf8 when sending
and back to the given encoding when receiving. The usage is:
<pre>
my $gateway = new AMF::Perl;
$gateway->encoding("iso-8859-7");
$gateway->setBaseClassPath("Services/");
$gateway->service();
</pre>

<a href=index.html>Go back to the AMF::Perl documentation</a>

doc/updates.html  view on Meta::CPAN

                <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.

		<br><br>Aug 3, 2003. Version 0.08 uploaded. Petstore example implemented!!! Also, rewrote Flash::FLAP::new() to accept both Flash::FLAP->new and $flap->new.

		<br><br>Jul 26, 2003. Version 0.07 uploaded. Fixed a bug that would wrongly detect end-of-file in the input data on Windows and replaced the "our" keyword that is not backwards-compatible. Created pseudo_query() in Util::Object that encapsulates th...

		<br><br>Jun 22, 2003. Version 0.06 uploaded. Added an example that talks to a database on the server side. This is implemented via Flash::FLAP::Sql::MysqlRecordSet.pm. Got rid of a couple of "uninitialized" warnings.

		<br><br>Apr 29, 2003. Version 0.05 uploaded. It supports Windows and mod_perl 1.

        <br><br>Apr 14, 2003 - FLAP renamed to Flash::FLAP. Version 0.03 uploaded. Added ser

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

=over 4

=item Another patch from Kostas Chatzikokolakis fixing MP2 issues.

=back

=head2 Sat Mar 13 16:25:00 EST 2004

=over 4

=item Patch from Kostas Chatzikokolakis handling encoding.

=item Changed non-mod_perl behavior for reading POST data from using <> to using read()
to work around a bug in IIS

=item Joined code for mod_perl 1 and 2. Separated the output code for the mod_perl and non-mod_perl
cases.

=back

=head2 Sat Aug  2 14:01:15 EDT 2003

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


    $file = $self->debugDir."input.amf" unless $file;

    # temporary load the contents from a file
    my $content = $self->_loadRawDataFromFile($file);

    # build the input stream object from the file contents
    my $inputStream = new AMF::Perl::IO::InputStream($content);
    
    # build the deserializer and pass it a reference to the inputstream
    my $deserializer = new AMF::Perl::IO::Deserializer($inputStream, $self->{encoding});
    
    # get the returned Object
    my $amfin = $deserializer->getObject();

    return $amfin;
}

sub _service
{
    my ($self, $content) = @_;

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

    	$content = $self->_loadRawDataFromFile($self->debugDir."/input.amf");
    
        # save the raw amf data to a file
        #$self->_saveRawDataToFile ($self->debugDir."/input.amf", $content);
    }
    
    # build the input stream object from the file contents
    my $inputStream = new AMF::Perl::IO::InputStream($content);
    
    # build the deserializer and pass it a reference to the inputstream
    my $deserializer = new AMF::Perl::IO::Deserializer($inputStream, $self->{encoding});
    
    # get the returned Object
    my $amfin = $deserializer->getObject();
    
    # we can add much functionality with the headers here, like turn on server debugging, etc.
    my $headercount = $amfin->numHeader();
    
    for (my $i=0; $i<$headercount; $i++)
    {
        my $header = $amfin->getHeaderAt($i);

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

        } 

        # 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 ();

    # create a new serializer
    my $serializer = new AMF::Perl::IO::Serializer ($outstream, $self->{encoding});
    
    # serialize the data
    $serializer->serialize($amfout);

    if(0)
    {
        # save the raw data to a file for debugging
        $self->_saveRawDataToFile ($self->debugDir."/results.amf", $outstream->flush());
    }

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

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


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

sub encoding
{
	my $self = shift;
	$self->{encoding} = shift if @_;
	return $self->{encoding};
}

#    usefulldebugging method 
#    You can save the raw  data sent from the
#    flash client by calling
#    $self->_saveRawDataToFile("file.amf",  $contents);

sub _saveRawDataToFile
{
    my ($self, $filepath, $data)=@_;

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

    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

=item Fixed reading keys of objects.

=item Added floor(), as Perl lacks it.

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


  return int($n) - ($n < 0 ? 1: 0) * ($n != int($n) ? 1 : 0);
}


#******************** PUBLIC METHODS ****************************/

# constructor that also dserializes the raw data
sub new
{
    my ($proto, $is, $encoding)=@_;
    my $self = {};
    bless $self, $proto;
    # the object to store the deserialized data
    $self->{amfdata} = new AMF::Perl::Util::Object();
    # save the input stream in this object
    $self->{inputStream} = $is;
	# save the encoding in this object
	$self->{encoding} = $encoding;
    # read the binary header
    $self->readHeader();
    # read the binary body
    $self->readBody();
    return $self;
}

# returns the instance of the Object package
sub getObject
{

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

    # grab the int value of the next byte
    my $int = $self->{inputStream}->readByte();
    # if it's a 0x01 return true else return false
    return ($int == 1);
}

sub readString
{
    my ($self)=@_;
    my $s = $self->{inputStream}->readUTF();
	from_to($s, "utf8", $self->{encoding}) if $self->{encoding};
	return $s;
}

sub readDate
{
    my ($self)=@_;
    my $ms = $self->{inputStream}->readDouble(); # date in milliseconds from 01/01/1970

    # nasty way to get timezone 
    my $int = $self->{inputStream}->readInt();

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

    # is there a nice way to return entire date(milliseconds and timezone) in PHP???
    return $ms; 
}

# XML comes in as a plain string except it has a long displaying the length instead of a short?
sub readXML
{
    my ($self)=@_;
        # reads XML
    my $rawXML = $self->{inputStream}->readLongUTF();
	from_to($rawXML, "utf8", $self->{encoding}) if $self->{encoding};
    
    # maybe parse the XML into a PHP XML structure??? or leave it to the developer
    
    # return the xml
    return $rawXML;
}
sub readFlushedSO
{
    my ($self)=@_;
    # receives [type(07) 00 00] if SO is flushed and contains 'public' properties

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


=item Made basic data type determination work for both scalars and scalarrefs.

=item Now we check if we are sending a recordset and setting column types accordingly.

=head2 Sat Mar 13 16:25:00 EST 2004

=item Patch from Tilghman Lesher that detects numbers and dates in strings
and sets return type accordingly.

=item Patch from Kostas Chatzikokolakis handling encoding and sending null value.

=head2 Sun May 11 16:43:05 EDT 2003

=item Changed writeData to set type to "NULL" when the incoming data is undef. Previously
it became a String, just like other scalars.

=item Changed PHP's writeRecordset to a generic writeAMFObject. Verified Recordset support.

=head2 Sun Mar  9 18:20:16 EST 2003

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

use strict;

use Encode qw/from_to/;
use DBI;

# holder for the data
my $data;

sub new
{	
    my ($proto, $stream, $encoding) = @_;
    # save
    my $self={};
    bless $self, $proto;
    $self->{out} = $stream;
	$self->{encoding} = $encoding;
    return $self;
}

sub serialize
{
    my ($self, $d) = @_;
    $self->{amfout} = $d;
    # write the version ???
    $self->{out}->writeInt(0);
    

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

    $self->{out}->writeByte($d);
}
# writes a string under 65536 chars, a longUTF is used and isn't complete yet
sub writeString
{
    my ($self, $d)=@_;
    # write the string code
    $self->{out}->writeByte(2);
    # write the string value
    #$self->{out}->writeUTF(utf8_encode($d));
	from_to($d, $self->{encoding}, "utf8") if $self->{encoding};
    $self->{out}->writeUTF($d);
}

sub writeXML
{
    my ($self, $d)=@_;
    $self->{out}->writeByte(15);
    #$self->{out}->writeLongUTF(utf8_encode($d));
	from_to($d, $self->{encoding}, "utf8") if $self->{encoding};
    $self->{out}->writeLongUTF($d);
}

# must be used PHPRemoting with the service to set the return type to date
# still needs a more in depth look at the timezone
sub writeDate
{
    my ($self, $d)=@_;
    # write date code
    $self->{out}->writeByte(11);



( run in 0.501 second using v1.01-cache-2.11-cpan-a5abf4f5562 )