%def .page>
This illustrates the periodically_call_remote function from the
HTML::Prototype package in a Mason Environment. The image on
the page will change from henry to jack to nadine to valerie
every 5 seconds.
Image goes here.
Name goes here.
Counter goes here.
Actually, the photos above do not use the HTML::Prototype
function periodically_call_remote, but my own little Javascript
function, runPeriodically defined above.
<& view_source , caller => 'self' &>
%def>
% ################################################################
<%init>
my @names = qw(henry jack nadine valerie);
if (exists $ARGS{data}) {
my $n = $ARGS{data};
my @response;
my $name = $names[ $n++ % scalar @names ] . '.jpg';
my $url = $m->request_comp->path . "?data=$n";
@response = $n > 10 ?
(
$p->update_element_function
('myUpdate',
{action => 'update',
content => "That is enough"
}),
$p->update_element_function
('myName',
{action => 'update',
content => $name
}),
$p->update_element_function
('myCount',
{action => 'update',
content => $n
}),
) :
(
$p->update_element_function
('myUpdate',
{action => 'update',
content => "
"
}),
$p->update_element_function
('myName',
{action => 'update',
content => $name
}),
$p->update_element_function
('myCount',
{action => 'update',
content => $n
}),
"runPeriodically('$url',5,'myUpdate');"
) ; # end of @response
$m->print(@response);
} else {
$m->comp('.page');
}
%init>
<%shared>
my $p = HTML::Prototype->new();
%shared>