| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Flash::FLAP::Util::Object; | 
| 2 |  |  |  |  |  |  | # Copyright (c) 2003 by Vsevolod (Simon) Ilyushchenko. All rights reserved. | 
| 3 |  |  |  |  |  |  | # This program is free software; you can redistribute it and/or modify it | 
| 4 |  |  |  |  |  |  | # under the same terms as Perl itself. | 
| 5 |  |  |  |  |  |  | # The code is based on the -PHP project (http://amfphp.sourceforge.net/) | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Flash::FLAP::Object | 
| 10 |  |  |  |  |  |  | Translated from PHP Remoting v. 0.5b from the -PHP project. | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Package used for building and retreiving  header and body information | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 CHANGES | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | Sun Jul 27 16:52:12 EDT 2003 | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =item Added the pseudo_query() method to create a recordset object wanted by Flash. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =cut | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 520 |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # constructor | 
| 27 |  |  |  |  |  |  | sub new | 
| 28 |  |  |  |  |  |  | { | 
| 29 | 0 |  |  | 0 | 0 |  | my ($proto)=@_; | 
| 30 | 0 |  |  |  |  |  | my $self = {}; | 
| 31 | 0 |  |  |  |  |  | bless $self, $proto; | 
| 32 |  |  |  |  |  |  | # init the headers and bodys arrays | 
| 33 | 0 |  |  |  |  |  | $self->{_headers} = []; | 
| 34 | 0 |  |  |  |  |  | $self->{_bodies} = []; | 
| 35 | 0 |  |  |  |  |  | return $self; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | # adds a header to our object | 
| 39 |  |  |  |  |  |  | # requires three arguments key, required, and value | 
| 40 |  |  |  |  |  |  | sub addHeader | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 0 |  |  | 0 | 0 |  | my ($self, $k, $r, $v)=@_; | 
| 43 | 0 |  |  |  |  |  | my $header = {}; | 
| 44 | 0 |  |  |  |  |  | $header->{"key"} = $k; | 
| 45 | 0 |  |  |  |  |  | $header->{"required"} = $r; | 
| 46 | 0 |  |  |  |  |  | $header->{"value"} = $v; | 
| 47 | 0 |  |  |  |  |  | push @{$self->{_headers}}, $header; | 
|  | 0 |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # returns the number of headers | 
| 51 |  |  |  |  |  |  | sub numHeader | 
| 52 |  |  |  |  |  |  | { | 
| 53 | 0 |  |  | 0 | 0 |  | my ($self)=@_; | 
| 54 | 0 |  |  |  |  |  | return scalar(@{$self->{_headers}}); | 
|  | 0 |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub getHeaderAt | 
| 58 |  |  |  |  |  |  | { | 
| 59 | 0 |  |  | 0 | 0 |  | my ($self, $id)=@_; | 
| 60 | 0 | 0 |  |  |  |  | $id=0 unless $id; | 
| 61 | 0 |  |  |  |  |  | return $self->{_headers}->[$id]; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # adds a body to our bodys object | 
| 65 |  |  |  |  |  |  | # requires three arguments target, response, and value | 
| 66 |  |  |  |  |  |  | sub addBody | 
| 67 |  |  |  |  |  |  | { | 
| 68 | 0 |  |  | 0 | 0 |  | my ($self, $t, $r, $v, $ty)=@_; | 
| 69 | 0 | 0 |  |  |  |  | $ty="unknown" unless $ty; | 
| 70 | 0 |  |  |  |  |  | my $body = {}; | 
| 71 | 0 |  |  |  |  |  | $body->{"target"} = $t; | 
| 72 | 0 |  |  |  |  |  | $body->{"response"} = $r; | 
| 73 | 0 |  |  |  |  |  | $body->{"value"} = $v; | 
| 74 | 0 |  |  |  |  |  | $body->{"type"} = $ty; | 
| 75 | 0 |  |  |  |  |  | push @{$self->{_bodies}}, $body; | 
|  | 0 |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | # returns the number of body elements | 
| 78 |  |  |  |  |  |  | sub numBody | 
| 79 |  |  |  |  |  |  | { | 
| 80 | 0 |  |  | 0 | 0 |  | my ($self)=@_; | 
| 81 | 0 |  |  |  |  |  | return scalar(@{$self->{_bodies}}); | 
|  | 0 |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  | # returns the body element at a specific index | 
| 84 |  |  |  |  |  |  | sub getBodyAt | 
| 85 |  |  |  |  |  |  | { | 
| 86 | 0 |  |  | 0 | 0 |  | my ($self, $id)=@_; | 
| 87 | 0 | 0 |  |  |  |  | $id=0 unless $id; | 
| 88 | 0 |  |  |  |  |  | return $self->{_bodies}->[$id]; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub pseudo_query | 
| 92 |  |  |  |  |  |  | { | 
| 93 | 0 |  |  | 0 | 1 |  | my ($self, $columnNames, $data) = @_; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 0 |  |  |  |  |  | my $result = new Flash::FLAP::Util::Object; | 
| 96 |  |  |  |  |  |  | # create the serverInfo array | 
| 97 | 0 |  |  |  |  |  | $result->{"serverInfo"} = {}; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | # create an initialData array | 
| 100 | 0 |  |  |  |  |  | my (@initialData, @columnNames); | 
| 101 | 0 |  |  |  |  |  | $result->{serverInfo}->{initialData} = $data; | 
| 102 | 0 |  |  |  |  |  | $result->{serverInfo}->{columnNames} = $columnNames; | 
| 103 | 0 |  |  |  |  |  | $result->{serverInfo}->{totalCount}= scalar @$data; | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | # create the id field --> i think this is used for pageable recordsets | 
| 106 | 0 |  |  |  |  |  | $result->{"serverInfo"}->{"id"} = "FLAP"; | 
| 107 | 0 |  |  |  |  |  | $result->{"serverInfo"}->{"cursor"} = 1; # maybe the current record ???? | 
| 108 | 0 |  |  |  |  |  | $result->{"serverInfo"}->{"serviceName"} = "doStuff"; # in CF this is PageAbleResult not here | 
| 109 |  |  |  |  |  |  | # versioning | 
| 110 | 0 |  |  |  |  |  | $result->{"serverInfo"}->{"version"} = 1; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 0 |  |  |  |  |  | $result->{_explicitType}='RecordSet'; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  |  | return $result; | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | 1; |