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;
| [reply] [d/l] [select] |
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;
-*- mode: compilation; default-directory: "d:/tmp/pm/" -*-
Compilation started at Mon Dec 28 18:09:17
C:/Perl_524/bin\perl.exe -w d:/tmp/pm/create_class.pl
Jabba::Dabba imported at (eval 2) line 5.
$VAR1 = {
'overloading.pm' => 'C:/Perl_524/lib/overloading.pm',
'Data/Dumper.pm' => 'C:/Perl_524/lib/Data/Dumper.pm',
'overload.pm' => 'C:/Perl_524/lib/overload.pm',
'strict.pm' => 'C:/Perl_524/lib/strict.pm',
'warnings/register.pm' => 'C:/Perl_524/lib/warnings/register
+.pm',
'bytes.pm' => 'C:/Perl_524/lib/bytes.pm',
'Jabba/Dabba.pm' => 'imported via eval at main d:/tmp/pm/cre
+ate_class.pl 39',
'Carp.pm' => 'C:/Perl_524/lib/Carp.pm',
'C:/Perl_524/site/lib/sitecustomize.pl' => 'C:/Perl_524/site
+/lib/sitecustomize.pl',
'XSLoader.pm' => 'C:/Perl_524/lib/XSLoader.pm',
'constant.pm' => 'C:/Perl_524/lib/constant.pm',
'warnings.pm' => 'C:/Perl_524/lib/warnings.pm',
'Exporter.pm' => 'C:/Perl_524/lib/Exporter.pm'
};
Compilation finished at Mon Dec 28 18:09:17
| [reply] [d/l] [select] |
I wrote my last reply at 3.13am (my time).
I did see your response about 10 minutes later but my eyes were getting pretty blurry by then:
I decided some sleep was in order before looking into that further. :-)
Twelve hours later, and much refreshed, I see you've posted a lot more code.
Thanks for that — I'll look into it and see how that fits with my existing code.
| [reply] |