Changeset 817

Show
Ignore:
Timestamp:
05/24/06 22:38:32
Author:
miyagawa
Message:
  • semi-singletonize Cookies instances
  • auto guess cookie type if it's hash without type
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Cookies.pm

    r807 r817  
    44use UNIVERSAL::require; 
    55 
     6our %Instances; 
     7 
    68sub create { 
    79    my($class, $conf) = @_; 
    810 
    9     unless (ref $conf) { 
    10         $conf = $class->auto_guess($conf)
    11         Plagger->context->log(debug => "$conf->{file} => $conf->{type}") if $conf->{type}
     11    unless (ref $conf && $conf->{type}) { 
     12        my $file = ref $conf ? $conf->{file} : $conf
     13        $conf = $class->auto_guess($file)
    1214    } 
    1315 
    14     my $type = delete $conf->{type}; 
    15     my $impl = $type ? "HTTP::Cookies::$type" : "HTTP::Cookies"; 
    16     $impl->require or Plagger->context->error("Error loading $impl: $@"); 
     16    $Instances{$conf->{file}} ||= do { 
     17        my $type = delete $conf->{type}; 
     18        my $impl = $type ? "HTTP::Cookies::$type" : "HTTP::Cookies"; 
     19        Plagger->context->log(debug => "$conf->{file} => $impl"); 
     20        $impl->require or Plagger->context->error("Error loading $impl: $@"); 
    1721 
    18     $impl->new(%$conf); 
     22        $impl->new(%$conf); 
     23    }; 
    1924} 
    2025