[libmixin-extrafields-param-perl] 11/25: r19787 at knave: rjbs | 2006-03-14 18:22:16 -0500 better docs, add delete_param

Florian Schlichting fsfs at moszumanska.debian.org
Wed Jan 29 21:00:23 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 437e306c5e4ea00d0751ec4cc6b26eb8755b23f2
Author: Ricardo SIGNES <rjbs at codesimply.com>
Date:   Wed Mar 15 01:16:29 2006 +0000

     r19787 at knave:  rjbs | 2006-03-14 18:22:16 -0500
     better docs, add delete_param
---
 Changes            |  2 +-
 Makefile.PL        |  2 +-
 README             | 33 ++++++++++-----------------------
 lib/Mixin/Param.pm | 54 +++++++++++++++++++++++++++++++++++++++---------------
 4 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/Changes b/Changes
index 28b9fc6..4f57769 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,5 @@
 Revision history for Mixin-Param
 
-0.01    Date/time
+0.01    2006-03-13
         First version, released on an unsuspecting world.
 
diff --git a/Makefile.PL b/Makefile.PL
index a287981..0a7de6f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -10,7 +10,7 @@ WriteMakefile(
     PL_FILES            => {},
     PREREQ_PM => {
         'Scalar::Util'      => 0,
-        'Sub::Install'      => 0.03,
+        'Sub::Exporter'     => 0.90,
         'Test::More'        => 0,
         'Tie::RefHash:Weak' => 0.01,
     },
diff --git a/README b/README
index e34653b..2d0b6b8 100644
--- a/README
+++ b/README
@@ -1,31 +1,18 @@
-Mixin-Param
+Mixin::Param - make your class provide a familiar "param" method
 
-The README is used to introduce the module and provide instructions on
-how to install the module, any machine dependencies it may have (for
-example C compilers and installed libraries) and any other information
-that should be provided before the module is installed.
+SYNOPSIS
 
-A README file is required for CPAN modules since CPAN extracts the README
-file from a module distribution so that people browsing the archive
-can use it get an idea of the modules uses. It is usually a good idea
-to provide version information here so that people can decide whether
-fixes for the module are worth downloading.
+  package Widget::Parametric;
+  use Mixin::Param;
 
-INSTALLATION
+  ...
 
-To install this module, run the following commands:
+  my $widget = Widget::Parametric->new({ flavor => 'vanilla' });
 
-    perl Makefile.PL
-    make
-    make test
-    make install
+  printf "%s: %s\n", $_, $widget->param($_) for $widget->param;
 
+DESCRIPTION
 
-COPYRIGHT AND LICENCE
+This module mixes in to your class to provide a C<param> method like the ones
+provided by L<CGI>, L<CGI::Application>, and other classes.
 
-Put the correct copyright and licence information here.
-
-Copyright (C) 2005 Ricardo Signes
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
diff --git a/lib/Mixin/Param.pm b/lib/Mixin/Param.pm
index f867f4f..7c35f40 100644
--- a/lib/Mixin/Param.pm
+++ b/lib/Mixin/Param.pm
@@ -5,9 +5,13 @@ use strict;
 
 use Carp ();
 use Scalar::Util ();
-use Sub::Install ();
 use Tie::RefHash::Weak;
 
+use Sub::Exporter -setup => {
+  exports  => [ qw(param) ],
+  groups   => { default => [ qw(param) ] },
+};
+
 =head1 NAME
 
 Mixin::Param - make your class provide a familiar "param" method
@@ -52,7 +56,8 @@ provided by L<CGI>, L<CGI::Application>, and other classes.
 
 =cut
 
-tie my %_params_for, 'Tie::RefHash::Weak';
+my %_params_for;
+BEGIN { tie %_params_for, 'Tie::RefHash::Weak'; }
 
 sub __params_storage_guts { %_params_for }
 
@@ -76,31 +81,50 @@ sub param {
     return $stash->{$key};
   }
 
-  my @return;
+  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 @return, $value;
+    push @assigned, $value;
   }
-  return wantarray ? @return : $return[0];
+  return wantarray ? @assigned : $assigned[0];
 }
 
-sub import {
-  my ($class, $import_as) = @_;
-  my $into = caller(0);
-  $import_as ||= 'param';
+=head2 C< delete_param >
+
+ my $deleted = $object->delete_param('name'); # delete the param entirely
+
+ my @deleted = $object->delete_param(@names); # delete several params
+
+ my $deleted = $object->delete_param(@names); # returns the first deleted value
+
+=cut
+
+sub delete_param {
+  my $self = shift;
+  my (@keys) = @_;
+  
+  Carp::croak "delete_param is an instance method"
+    unless Scalar::Util::blessed($self);
+
+  my $stash = $_params_for{ $self } ||= {};
 
-  Sub::Install::install_sub({
-    code => \&param,
-    into => $into, 
-    as   => $import_as
-  });
+  my @deleted = map { scalar delete $stash->{$_} } @keys;
+
+  return wantarray ? @deleted : $deleted[0];
 }
 
 =head1 AUTHOR
 
 Ricardo Signes, C<< <rjbs at cpan.org> >>
 
+=head2 THANKS
+
+Thanks to Yuval Kogman, not only for writing Tie::WeakRefHash, but for pointing
+it out to me when I said that someone should write it.
+
 =head1 BUGS
 
 Please report any bugs or feature requests to
@@ -110,7 +134,7 @@ notified of progress on your bug as I make changes.
 
 =head1 COPYRIGHT
 
-Copyright 2005 Ricardo Signes, All Rights Reserved.
+Copyright 2005-2006 Ricardo Signes, All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

-- 
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