CGI-JSONRPC

 view release on metacpan or  search on metacpan

lib/CGI/JSONRPC/Session.pm  view on Meta::CPAN

package CGI::JSONRPC::Session;

use CGI::JSONRPC;
use CGI::JSONRPC::Dispatcher::Session;
use base qw(CGI::JSONRPC);


1;

sub new {
    my($class,%args) = @_;
    %args = __PACKAGE__->init_session(%args);
    return bless { dispatcher => $class->default_dispatcher, %args }, $class;
}

sub cgi_session_dsn {
  my $class = shift;
  return "driver:file;serializer:yaml";
}

# should set the args with a session arg
sub init_session {
   my ($class,%args) = @_;
   if ($args{cgi} and ref($args{cgi})) {
       require CGI::Session;
       $args{session} = CGI::Session->new($class->cgi_session_dsn(), $args{cgi});  
       $args{session}->flush();  # just in case :)
   } else {
     warn __PACKAGE__ . " unable to find a cgi argument, cannot restore session\n";
   }
   return %args;      
}


sub headers_js {
  my $self = shift;
  $self->{session}->header('Content-Type' => "text/javascript");
}

sub headers_json {
  my $self = shift;
  $self->{session}->header('Content-Type' => "text/json");
}


sub default_dispatcher {
    'CGI::JSONRPC::Dispatcher::Session'
}


=pod

=head1 NAME

CGI::JSONRPC::Session - Persistant CGI handler for JSONRPC

=head1 SYNOPSIS


  use CGI;
  use MyDispatcher
  my $cgi = new CGI;
  MyDispatcher->handler($cgi);
  exit;
  
  package MyDispatcher;

  sub init_session {
    my ($class,%args) = @_;
    require CGI::Session;
    $args{session} = CGI::Session->new($args{cgi});
    return %args;
  }

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.007 second using v1.00-cache-1.14-grep-28634ff-cpan-207214f8fbd )