[Bio] / FigKernelPackages / raelib.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/raelib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26, Fri Aug 5 16:22:53 2005 UTC revision 1.27, Mon Oct 3 20:05:34 2005 UTC
# Line 24  Line 24 
24  =cut  =cut
25    
26  sub new {  sub new {
27   my $self=shift;   my ($class)=@_;
28   return $self   my $self={};
29     return bless $self, $class;
30  }  }
31    
32    
# Line 707  Line 708 
708   return $seq;   return $seq;
709  }  }
710    
711    
712    =head2 cookies
713    
714    Handle cookies. This method will get and set the value of the FIG cookie. Cookies are name/value pairs that are stored on the users computer. We then retrieve them using this method. The cookies are passed in as a reference to a hash, and the method returns a tuple of the cookie that can be passed to the browser and a reference to a hash with the data.
715    
716    If you do not pass any arguments the whole cookie will be returned.
717    
718    Use as follows:
719    
720    ($cookie, $data) = raelib->cookie($cgi, \%data);
721    
722    You do not need to pass in any data, in that case you will just get the cookie back
723    
724    Underneath, I create a single cookie called FIG which stores all the information. The names and value pairs are stored using = to join name to value and ; to concatenate. This way we can create a single cookie with all the data. I am using the FIG::clean_attribute_key method to remove unwanted characters from the name/value pairs, so don't use them.
725    
726    Note that for the moment I have put this routine here since it needs to maintain the state of the cookie (i.e. it needs to know what $self is). It should really be in HTML.pm but that is not, as far as I can tell, maintaining states?
727    
728    =cut
729    
730    sub cookie {
731     my ($self, $cgi, $input)=@_;
732     return unless ($cgi);
733     $self->{'cookie'}=$cgi->cookie(-name=>"FIG") unless ($self->{'cookie'});
734    
735     # first, create a hash from the existing cookie data
736     my $cookie;
737     map {
738      my ($kname, $kvalue)=split /\=/, $_;
739      $cookie->{$kname}=$kvalue;
740     } split /\;/, $self->{'cookie'};
741    
742     if ($input)
743     {
744      # add the values that were passed in
745      map {$cookie->{FIG->clean_attribute_key($_)}=$input->{$_}} keys %$input;
746      # put everything back together and set the cookie
747      my $newcookie=join ";", map {$_ . "=" . $cookie->{$_}} keys %$cookie;
748      $self->{'cookie'}=$cgi->cookie(-name=>"FIG", -value=>$newcookie, -expires=>'+1y');
749     }
750    
751     return ($self->{'cookie'}, $cookie);
752    }
753    
754    
755    
756    
757  1;  1;
758    

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3