in reply to Problem emulating use

I suppose the problem is that you're trying to read from __DATA__ more than once...  Try storing the initial file pointer position using tell, and then seek to that position before your while (<DATA>) {...} loop.  Alternatively, load the template code into a variable that you can then use repeatedly...

Replies are listed 'Best First'.
Re^2: Problem emulating use
by Bloodnok (Vicar) on Jul 11, 2008 at 12:21 UTC
    TFT Almut
    You're a hair saver !! :-))
    Just the insight I needed - declaring a package variable, $template, and changing define() to...
    sub define { my $self = shift; my $type = shift || croak "No type name"; unless ($template) { local $/ = undef; $template = <DATA>; } my ($code, $parent, $subclass) = ($template, __PACKAGE__, __PACKAGE__ . "\::$type"); $code =~ s,##PACKAGE##,$subclass,g; $code =~ s,##PARENT##,$parent,g; { my $WARNING = ''; local $SIG{__WARN__} = sub { $WARNING = "@_" }; eval $code; croak "Failed to create subclass: $subclass - $WARNING$@" if $WARNING || $@; croak "Problem with subclass: $subclass - cannot new()" unless $subclass->can(qw/new/); } print STDERR "Created type: $type\n"; }
    ... works fine.
    Thanx again

    At last, a user level that overstates my experience :-))