Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^6: require() @INC hooks problem

by LanX (Saint)
on Dec 28, 2020 at 16:35 UTC ( [id://11125877]=note: print w/replies, xml ) Need Help??


in reply to Re^5: require() @INC hooks problem
in thread require() @INC hooks problem

here tested code
use strict; use warnings; use Data::Dump qw/pp dd/; sub create_class { my ($class) = @_; my $source = <<"__CODE__"; package $class; sub import { warn "$class imported"; } __CODE__ eval $source; my $name = $class =~ s(::)(\/)gr; $INC{"$name.pm"} = 'imported via eval'; } BEGIN { create_class('Jabba::Dabba'); } pp \%INC; use Jabba::Dabba;

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^7: require() @INC hooks problem
by LanX (Saint) on Dec 28, 2020 at 17:04 UTC
    fixed module template, less Perl version dependencies, more flexible and untangled templating

    use strict; use warnings; use Data::Dumper; sub test_tmpl { my ($name) = @_; return $name, <<"__CODE__"; package $name; sub import { warn "$name imported"; } 1; __CODE__ } sub create_module { my ( $module, $source ) = @_; eval $source; (my $name = $module) =~ s(::)(\/)g; my @caller = caller(); $INC{"$name.pm"} = "imported via eval at @caller"; } BEGIN { create_module( test_tmpl('Jabba::Dabba') ); } use Jabba::Dabba; warn Dumper \%INC;

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125877]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found