Permalink
Browse files

Hopts status

readonly function
  • Loading branch information...
1 parent 7721841 commit f3f4b7a33c34c52e8d150559955bd5da9ea54175 @jamhed jamhed committed Nov 19, 2010
Showing with 30 additions and 4 deletions.
  1. +5 −4 lib/selfvars.pm
  2. +10 −0 t/0hopts.t
  3. +15 −0 t/lib/HOpts.pm
View
@@ -156,20 +156,21 @@ sub _opts {
};
$level++;
}
+ shift @DB::args;
@DB::args;
}
sub readonly { require Carp; Carp::croak('Modification of a read-only %args attempted'); }
sub TIEHASH { my $x; bless \$x => $_[0] }
-sub FETCH { my (undef, %o) = _opts(); $o{ $_[1] } }
+sub FETCH { my (%o) = _opts(); $o{ $_[1] } }
sub STORE { readonly }
-sub FIRSTKEY { my (undef, %o) = _opts(); my $a = scalar keys %o; each %o }
+sub FIRSTKEY { my (%o) = _opts(); my $a = scalar keys %o; each %o }
sub NEXTKEY { }
-sub EXISTS { my (undef, %o) = _opts(); exists $o{$_[1]} }
+sub EXISTS { my (%o) = _opts(); exists $o{$_[1]} }
sub DELETE { readonly }
sub CLEAR { readonly }
-sub SCALAR { my (undef, %o) = _opts(); scalar %o }
+sub SCALAR { my (%o) = _opts(); scalar %o }
package selfvars;
View
@@ -0,0 +1,10 @@
+
+use lib 't/lib';
+use HOpts;
+use Test::More tests => 1;
+
+{
+ my $o = HOpts->new;
+ is($o->hopts( param => 2 ), '0 2');
+}
+
View
@@ -0,0 +1,15 @@
+use strict;
+
+package HOpts;
+use selfvars -self => 'this', -args => 'vars', -opts => 'vars', -hopts => 'args';
+
+sub new {
+ my $class = shift;
+ return bless { v => 0 }, $class;
+}
+
+sub hopts {
+ return join ' ', $this->{v}, $args{'param'};
+}
+
+1;

0 comments on commit f3f4b7a

Please sign in to comment.