Skip to content

Commit

Permalink
0.15 ANON defeat
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Apr 18, 2009
1 parent b092294 commit ecd41ca
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 30 deletions.
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
---
version: 0.15
date: Sat Apr 18 09:21:21 PDT 2009
change:
- Make stack trace not say ANON

---
version: 0.14
date: Fri Apr 25 12:20:38 CST 2008
Expand Down
25 changes: 0 additions & 25 deletions MANIFEST

This file was deleted.

14 changes: 14 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
^MANIFEST\.SKIP$
^.git/
^.gitignore
^Makefile$
^pm_to_blib$
^blib
^\.vimrc$
^pyyaml
^init.py$
^Notes$
^ToDo$
^BPW-Talk
^Review
^Hacks/
8 changes: 4 additions & 4 deletions lib/Class/Field.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use warnings;
use base 'Exporter';
use Encode;

our $VERSION = '0.14';
our $VERSION = '0.15';
our @EXPORT_OK = qw(field const);

my %code = (
sub_start =>
"sub {\n",
"sub {\n local \*__ANON__ = \"%s::%s\";\n",
set_default =>
" \$_[0]->{%s} = %s\n unless exists \$_[0]->{%s};\n",
init =>
Expand Down Expand Up @@ -53,7 +53,7 @@ sub field {
? '{}'
: default_as_code($default);

my $code = $code{sub_start};
my $code = sprintf $code{sub_start}, $package, $field;
if ($args->{-init}) {
my $fragment = $args->{-weak} ? $code{weak_init} : $code{init};
$code .= sprintf $fragment, $field, $args->{-init}, ($field) x 4;
Expand Down Expand Up @@ -199,7 +199,7 @@ Ingy döt Net <ingy@cpan.org>
=head1 COPYRIGHT
Copyright (c) 2006, 2008. Ingy döt Net.
Copyright (c) 2006, 2008, 2009. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Expand Down
23 changes: 23 additions & 0 deletions t/anon.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use lib 'lib';
use Test::More tests => 1;
use strict;

package Foo;
# use Class::Field -clean => 'field';
# use Class::Field -debug => 'field';
use Class::Field 'field';

sub new { return bless {}, shift }
print field x => -init => 'main::test1()';

package main;

my $f = Foo->new();

$f->x();

sub test1 {
my $name = (caller(1))[3];
is $name, 'Foo::x',
'ANON replaced with real sub name for field';
}
13 changes: 12 additions & 1 deletion t/field.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 8;
use Test::More tests => 9;

package Foo;
use base 't::Base';
Expand All @@ -9,6 +9,8 @@ field 'y' => [];
field 'z' => {};
field 'i', -init => '$self->hello';

my $xyz = field 'xyz';

sub hello {
my $self = shift;
return 'Howdy';
Expand Down Expand Up @@ -43,3 +45,12 @@ $foo->i('Goodbye');

is $foo->{i}, 'Goodbye',
'Setting field works';

is $xyz, <<'...', 'Code generation is right';
sub {
local *__ANON__ = "Foo::xyz";
return $_[0]->{xyz} unless $#_ > 0;
$_[0]->{xyz} = $_[1];
return $_[0]->{xyz};
}
...

0 comments on commit ecd41ca

Please sign in to comment.