Catalyst-Plugin-Snippets
view release on metacpan or search on metacpan
lib/Catalyst/Plugin/Snippets.pm view on Meta::CPAN
=item use_session_id
This fields allows you to automatically create a different "namespace" for each
user, when used in conjunction with L<Catalyst::Plugin::Session>.
This is false by default.
=item content_type
When the formatter type is C<plain> you may use this field to specify the
content-type header to use.
This option defaults to C<text/plain>.
=item json_content_type
Since no one seems to agree on what the "right" content type for JSON data is,
we have this option too ;-).
This option defaults to C<application/javascript+json>
=back
=head1 PRIVACY CONCERNS
Like session keys, if the values are private the key used by your code should
be sufficiently hard to guess to protect the privacy of your users.
Please use the C<use_session_id> option for the appropriate namespace unless
you have a good reason not to.
=head1 RECIPES
=head2 Ajax Progress Meter
Suppuse your app runs a long running process in the server.
sub do_it {
my ( $self, $c ) = @_;
IPC::Run::run(\@cmd);
# done
}
The user might be upset that this takes a long while. If you can track
progress, along these lines:
my $progress = 0;
IPC::Run::run(\@cmd, ">", sub {
my $output = shift;
$progress++ if ( $output =~ /made_progress/ );
});
then you can make use of this data to report progress to the user:
$c->snippet( progress => $task_id => ++$progress )
if ( $output =~ /made_progress/ );
Meanwhile, javascript code with timers could periodically poll the server using
an ajax request to update the progress level. To expose this data to the client
create an action somewhere:
sub progress : Local {
my ( $self, $c ) = @_;
$c->serve_snippet;
}
and have the client query for C<"/controller/progress/$task_id">.
=cut
( run in 1.002 second using v1.01-cache-2.11-cpan-39bf76dae61 )