Skip to content

@jberger /usex-declare.pm
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A basic use_from implementation
package UseX::Declare;
use strict;
use warnings;
use Carp;
use Devel::Declare ();
my $verbose = 0;
sub import {
my $class = shift;
my $opts = shift;
$verbose = $opts->{verbose} || 0;
my $caller = caller;
Devel::Declare->setup_for(
$caller,
{ 'use_from' => { const => \&rewrite_use_from } }
);
no strict 'refs';
*{$caller.'::use_from'} = sub {};
}
sub rewrite_use_from {
no strict 'refs';
my $linestr = Devel::Declare::get_linestr;
print STDERR "Got: $linestr" if $verbose;
my $caller = Devel::Declare::get_curstash_name;
$linestr =~ s/use_from\s+\$(\w+)/
my $varname = $caller . '::' . $1;
my $module =
(defined ${$varname})
? ${$varname}
: croak "Cannot access variable \$$varname";
"use_from; use $module"
/e;
print STDERR "Rewritten: $linestr" if $verbose;
Devel::Declare::set_linestr($linestr);
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.