#!/usr/bin/env perl package ReportingHandler; use strict; use warnings; sub new { my ($proto, %config) = @_; my $class = ref($proto) || $proto; my $self = bless \%config, $class; return $self; } sub debuglog { my ($self, @debugtext) = @_; print "DEBUG: ", join(' ', @debugtext), "\n"; } package main; use strict; use warnings; use PageCamel::Helpers::JavaScript; use Data::Dumper; my $reph = ReportingHandler->new(); my $memory; #print Dumper($reph); my $jscode = qq{ function initMemory() { memory.counter = 0; } function incCounter(amount) { memory.counter = memory.counter + amount; } function printCounter() { log("Current count is " + memory.counter); } }; { # First run print "First run\n"; my $jsh = PageCamel::Helpers::JavaScript->new(reph => $reph, timeout => 10, code => $jscode); $jsh->initMemory(); $jsh->call('printCounter'); $jsh->call('incCounter', 42); $jsh->call('printCounter'); $memory = $jsh->getMemory(); } print "Memory contents: ", $memory, "\n"; { # Second run print "Second run\n"; my $jsh = PageCamel::Helpers::JavaScript->new(reph => $reph, timeout => 10, code => $jscode); $jsh->setMemory($memory); $jsh->call('printCounter'); $jsh->call('incCounter', 23); $jsh->call('printCounter'); }