I'm writing "Yet Another Perl OO Framework", primarily for fun. This is meant to be as close to my style (which is oddly very close to Ruby) for my own personal code. I doubt I will ever release this to CPAN - it's largely meant for me to play with some of the odds corners of Perl. And, I've hit one of them.

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.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

In reply to How does strict determine if something is legally declared? by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.