Catalyst-Plugin-Snippets

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    allow_refs
        If this is disabled reference values will raise an error instead of
        being returned to the client.

        This is true by default.

    use_session_id
        This fields allows you to automatically create a different
        "namespace" for each user, when used in conjunction with
        Catalyst::Plugin::Session.

        This is false by default.

    content_type
        When the formatter type is "plain" you may use this field to specify
        the content-type header to use.

        This option defaults to "text/plain".

    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 "application/javascript+json"

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 "use_session_id" option for the appropriate namespace
    unless you have a good reason not to.

RECIPES
  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 "/controller/progress/$task_id".



( run in 1.371 second using v1.01-cache-2.11-cpan-39bf76dae61 )