[libmixin-extrafields-param-perl] 13/25: r20938 at knave: rjbs | 2006-04-12 22:35:24 -0400 make it export its own groups

Florian Schlichting fsfs at moszumanska.debian.org
Wed Jan 29 21:00:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

fsfs pushed a commit to annotated tag 0.001
in repository libmixin-extrafields-param-perl.

commit 3c89523143595ff7a82f49135cb6b0be6ac8ea38
Author: Ricardo SIGNES <rjbs at codesimply.com>
Date:   Thu Apr 13 02:47:16 2006 +0000

     r20938 at knave:  rjbs | 2006-04-12 22:35:24 -0400
     make it export its own groups
---
 MANIFEST           |   2 +-
 lib/Mixin/Param.pm | 107 ++++++++++++++++++++++++++++++-----------------------
 t/gc.t             |   4 +-
 3 files changed, 63 insertions(+), 50 deletions(-)

diff --git a/MANIFEST b/MANIFEST
index 566d29a..b768fda 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3,7 +3,7 @@ MANIFEST
 META.yml # Will be created by "make dist"
 Makefile.PL
 README
-lib/Does/Param.pm
+lib/Mixin/Param.pm
 t/00-load.t
 t/pod-coverage.t
 t/pod.t
diff --git a/lib/Mixin/Param.pm b/lib/Mixin/Param.pm
index ba05eb6..187ae20 100644
--- a/lib/Mixin/Param.pm
+++ b/lib/Mixin/Param.pm
@@ -8,8 +8,11 @@ use Scalar::Util ();
 use Tie::RefHash::Weak;
 
 use Sub::Exporter -setup => {
-  exports  => [ qw(param) ],
-  groups   => { default => [ qw(param) ] },
+  # exports  => [ param => \&_param_gen ],
+  groups   => {
+    default => [ '-param' ],
+    param   => \&_param_gen,
+  },
 };
 
 =head1 NAME
@@ -56,41 +59,48 @@ provided by L<CGI>, L<CGI::Application>, and other classes.
 
 =cut
 
-my %_params_for;
-BEGIN { tie %_params_for, 'Tie::RefHash::Weak'; }
+#my %_params_for;
+#BEGIN { tie %_params_for, 'Tie::RefHash::Weak'; }
 
-sub __params_storage_guts { %_params_for }
+#sub __params_storage_guts { %_params_for }
 
-sub param {
-  my $self = shift;
-  
-  Carp::croak "param is an instance method" unless Scalar::Util::blessed($self);
+sub _param_gen {
+  tie my %_params_for, 'Tie::RefHash::Weak';
 
-  my $stash = $_params_for{ $self } ||= {};
+  my %sub;
 
-  return keys %$stash unless @_;
+  $sub{__params_storage_guts} = sub { %_params_for };
 
-  @_ = %{$_[0]} if @_ == 1 and ref $_[0] eq 'HASH';
-  
-  Carp::croak "invalid call to param: odd, non-one number of params"
-    if @_ > 1 and @_ % 2 == 1;
+  $sub{param} = sub {
+    my $self = shift;
+    
+    Carp::croak "param is an instance method" unless Scalar::Util::blessed($self);
 
-  if (@_ == 1) {
-    my $key = $_[0];
-    return unless exists $stash->{$key};
-    return $stash->{$key};
-  }
+    my $stash = $_params_for{ $self } ||= {};
 
-  my @assigned;
-  while (@_) {
-    # We don't put @_ into a hash because we guarantee processing (and more
-    # importantly return) order. -- rjbs, 2006-03-14
-    my ($key, $value) = splice @_, 0, 2;
-    $stash->{$key} = $value;
-    push @assigned, $value;
-  }
-  return wantarray ? @assigned : $assigned[0];
-}
+    return keys %$stash unless @_;
+
+    @_ = %{$_[0]} if @_ == 1 and ref $_[0] eq 'HASH';
+    
+    Carp::croak "invalid call to param: odd, non-one number of params"
+      if @_ > 1 and @_ % 2 == 1;
+
+    if (@_ == 1) {
+      my $key = $_[0];
+      return unless exists $stash->{$key};
+      return $stash->{$key};
+    }
+
+    my @assigned;
+    while (@_) {
+      # We don't put @_ into a hash because we guarantee processing (and more
+      # importantly return) order. -- rjbs, 2006-03-14
+      my ($key, $value) = splice @_, 0, 2;
+      $stash->{$key} = $value;
+      push @assigned, $value;
+    }
+    return wantarray ? @assigned : $assigned[0];
+  };
 
 =head2 C< delete_param >
 
@@ -102,19 +112,19 @@ sub param {
 
 =cut
 
-sub delete_param {
-  my $self = shift;
-  my (@keys) = @_;
-  
-  Carp::croak "delete_param is an instance method"
-    unless Scalar::Util::blessed($self);
+  $sub{delete_param} = sub {
+    my $self = shift;
+    my (@keys) = @_;
+    
+    Carp::croak "delete_param is an instance method"
+      unless Scalar::Util::blessed($self);
 
-  my $stash = $_params_for{ $self } ||= {};
+    my $stash = $_params_for{ $self } ||= {};
 
-  my @deleted = map { scalar delete $stash->{$_} } @keys;
+    my @deleted = map { scalar delete $stash->{$_} } @keys;
 
-  return wantarray ? @deleted : $deleted[0];
-}
+    return wantarray ? @deleted : $deleted[0];
+  };
 
 =head2 C< has_param >
 
@@ -122,15 +132,18 @@ sub delete_param {
 
 =cut
 
-sub has_param {
-  my ($self, $key) = @_;
-  
-  Carp::croak "delete_param is an instance method"
-    unless Scalar::Util::blessed($self);
+  $sub{has_param} = sub {
+    my ($self, $key) = @_;
+    
+    Carp::croak "delete_param is an instance method"
+      unless Scalar::Util::blessed($self);
+
+    my $stash = $_params_for{ $self } ||= {};
 
-  my $stash = $_params_for{ $self } ||= {};
+    return exists $stash->{$key};
+  };
 
-  return exists $stash->{$key};
+  return \%sub;
 }
 
 =head1 AUTHOR
diff --git a/t/gc.t b/t/gc.t
index 0fb798d..8a72e1a 100644
--- a/t/gc.t
+++ b/t/gc.t
@@ -16,10 +16,10 @@ use Test::More 'no_plan';
   $widget->param(flavor => 'teaberry');
   $widget->param(size => 'big', limits => undef);
 
-  my %guts = Mixin::Param->__params_storage_guts;
+  my %guts = Widget::Parameterized->__params_storage_guts;
   ok(scalar %guts, "there are some params being stored universally (duh)");
   ok($guts{$widget}, "the widget has some params");
 }
 
-my %guts = Mixin::Param->__params_storage_guts;
+my %guts = Widget::Parameterized->__params_storage_guts;
 ok(!(scalar %guts), "post GC, there are no params being stored universally");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmixin-extrafields-param-perl.git



More information about the Pkg-perl-cvs-commits mailing list