dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
The class declaration code looks something like:
package Foo; #use strict; use Class; class { attr qw( foo bar ); isa 'Foo::Base'; method floozle => signature (Int, Int), body { my ($v1, $v2) = @_; $self->foo( $v1 ); return $self->get_bar( $v2 ); }; }; package main; my $obj = Foo->new; $foo->set_foo( 3 ); $foo->floozle( 9, 5 ); # These croak $foo->floozle() $foo->floozle( 9, 'a' );
The astute observer will notice that $self is never declared anywhere, yet this does work just fine ... so long as you're not under strict. And, I have no idea why.
Class::import() (called during use) creates $Class::self in the caller's namespace. I would think that the existence of this variable before the reference to $self is compiled in the body declaration would satisfy strict. But, it apparently doesn't. And, it's the oddest set of errors:
Variable "$self" is not imported at t/lib/Foo.pm line ##. Global symbol "$self" requires explicit package name at t/lib/Foo.pm l +ine ##.
"use diagnostics" doesn't help much:
Variable "%s" is not imported%s (F) While "use strict" in effect, you referred to a global variabl +e that you apparently thought was imported from another module, becau +se something else of the same name (usually a subroutine) is exported + by that module. It usually means you put the wrong funny character o +n the front of your variable.
So, my questions are:
The goal here is to avoid string eval. It's ok if a solution either requires a specific Perl version or XS. In fact, I'd love it if the solution required XS - I've been looking for an actual thing for me to get my feet wet in XS.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How does strict determine if something is legally declared?
by diotalevi (Canon) on Jan 10, 2006 at 03:53 UTC | |
|
Re: How does strict determine if something is legally declared?
by Errto (Vicar) on Jan 10, 2006 at 04:19 UTC | |
|
Re: How does strict determine if something is legally declared? (import)
by tye (Sage) on Jan 10, 2006 at 16:52 UTC | |
by haukex (Archbishop) on Feb 23, 2019 at 14:24 UTC | |
by jdporter (Paladin) on Feb 26, 2019 at 22:08 UTC | |
by Anonymous Monk on Feb 24, 2019 at 13:13 UTC | |
|
Re: How does strict determine if something is legally declared?
by PodMaster (Abbot) on Jan 10, 2006 at 03:56 UTC |