package CGI::Lazy;
use strict;
use JSON;
use CGI::Pretty;
use CGI::Lazy::Config;
use CGI::Lazy::Plugin;
use CGI::Lazy::DB;
use CGI::Lazy::DB::RecordSet;
use CGI::Lazy::Session;
use CGI::Lazy::Templa
umed to be the absolute path to the config file for the Lazy object. That file will be parsed as JSON.
tmplDir => Directory where Lazy will look for html templates. Absolute path to directory.
package CGI::Lazy::Widget::Composite;
use strict;
use JSON;
use CGI::Lazy::Globals;
use base qw(CGI::Lazy::Widget);
# for new composite types need the following: ajaxSelect<type> and dbwrite<type
axSelectParentChild {
my $self = shift;
my %args = @_;
my $incoming = $args{incoming} || from_json(($self->q->param('POSTDATA') || $self->q->param('keywords') || $self->q->param('XForms:Model')));
ctSelectableDataset {
my $self = shift;
my %args = @_;
my $incoming = $args{incoming} || from_json(($self->q->param('POSTDATA') || $self->q->param('keywords') || $self->q->param('XForms:Model')));
package CGI::Lazy::Widget;
use strict;
use JSON;
use Tie::IxHash;
use CGI::Lazy::Globals;
use CGI::Lazy::Widget::Dataset;
use CGI::Lazy::Widget::DomLoader;
use CGI::Lazy::Widget::Composite;
use CGI:
$validator->{$_->widgetID} = $_->validator for @widgetlist;
my $json = to_json($validator);
return '{"validator" : '.$json.', "html" : "'.$outgoingdata .'"}';
}
#------------------------
foreach my $object (keys %{$self->vars->{objects};}) {
$objectJs .= "var $object = JSON.parse('".to_json($self->vars->{objects}->{$object})."');\n";
}
$objectJs = $self->q->jsw
package CGI::Lazy::Config;
use strict;
use JSON;
use Carp;
use CGI::Lazy::Globals;
#-------------------------------------------------------------------------------
sub AUTOLOAD {
my $self = shift;
name = shift;
my $json;
my $conf;
if (ref $filename) {
$conf = $filename;
} else {
eval {
open IF, "< $CONFIGROOT/$filename" or croak $!;
while (<IF>) {
$json .= $_ unless ($_ =
F;
};
if ($@) {
$q->errorHandler->noConfig($filename);
}
eval {
$conf = from_json($json);
};
if ($@) {
$q->errorHandler->badConfig($filename);
}
}
my $self = {_q => $q,
package CGI::Lazy::Session;
use strict;
use JSON;
use CGI::Lazy::ID;
use CGI::Lazy::CookieMonster;
use CGI::Lazy::Session::Data;
use CGI::Lazy::Globals;
#-------------------------------------------
e sessionID = ?", $self->sessionID);
my $data = $results->[0]->[0];
if ($data) {
return from_json($data);
} else {
return;
}
}
#--------------------------------------------------------------
ime
my $var = {
created => $now,
updated => $now,
expires => $expires,
};
my $data = to_json($var);
$self->db->do($query, $sessionID, $data);
return $sessionID;
}
#-------------------
I::Lazy::Javascript::JSONParser;
use strict;
use Exporter;
use base qw(Exporter);
our @EXPORT = qw($JSONPARSER);
our $JSONPARSER = <<END;
//JSON Parser
if(!this.JSON){this.JSON={};}
(function(){fu
nction f(n){return n<10?'0'+n:n;}
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'
tUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
var cx=/[\\u0000\\u00ad\\u0600-\
package CGI::Lazy::Widget::Controller;
use strict;
use JSON;
use JavaScript::Minifier qw(minify);
use CGI::Lazy::Globals;
use base qw(CGI::Lazy::Widget);
#------------------------------------------
dname} = $value;
}
}
my $jscontrollername = $widgetID."Controller";
my $selectObject = to_json([map {{name => $_->{name}, required => $_->{required}}} @{$self->controls}]);
my $javascript =
package CGI::Lazy::Widget::Dataset;
use strict;
use JavaScript::Minifier qw(minify);
use JSON;
use CGI::Lazy::Globals;
use Tie::IxHash;
use base qw(CGI::Lazy::Widget);
our $tableCaptionVar = "
."Validator = ".to_json($self->validator).";");
my $primarykey = $self->recordset->primarykey;
my $searchObjectName = $self->widgetID.'SearchObject';
my $searchObject = to_json([map {$widgetID."-
s caused by network traffic. It's using AJAX and JSON, but there's no eval-ing. All data is passed into the browser as JSON, and washed though a JSON parser.
To do its magic, the Dataset relies he
package CGI::Lazy::Widget::DomLoader;
use strict;
use base qw(CGI::Lazy::Widget);
use JSON;
#----------------------------------------------------------------------------------------
sub new {
my $
foreach my $rawvar (keys %{$self->vars->{raw};}) {
$rawObjectJs .= "var $rawvar = JSON.parse('".to_json($self->vars->{raw}->{$rawvar})."');\n";
}
$rawObjectJs = $self->q->jswr
package CGI::Lazy::Javascript;
use strict;
use CGI::Lazy::Globals;
use CGI::Lazy::Javascript::JSONParser;
use JavaScript::Minifier qw(minify);
#javascript for ajax requests
our $AJAXJS = q[
functio
failed: "+ err);
}
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify(outgoing));
request.onreadystatechange = function() {
if (request.readyS
failed: "+ err);
}
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify(outgoing));
returnHandler(request.status, request.responseText);
}
];
#ja