Importer-Zim-Unit
view release on metacpan or search on metacpan
lib/Importer/Zim/Unit.pm view on Meta::CPAN
2021222324252627282930313233343536373839
my
$t
=
shift
;
@_
= %{
$_
[0] }
if
@_
== 1 &&
ref
$_
[0] eq
'HASH'
;
@_
=
map
{
$_
& 1 ?
$_
[
$_
] :
"${t}::$_[$_]"
} 0 ..
$#_
;
goto
&_export_to
;
}
sub
_export_to {
my
$old
= Sub::Replace::sub_replace(
@_
);
# Clean it up after compilation
Devel::Hook->unshift_UNITCHECK_hook(
sub
{
warn
qq{ Restoring @{[map qq{"$_"}
,
sort
keys
%$old
]}\n}
if
DEBUG;
Sub::Replace::sub_replace(
$old
);
}
)
if
%$old
;
}
no
Importer::Zim::Utils
qw(DEBUG )
;
lib/Importer/Zim/Unit.pm view on Meta::CPAN
767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134#pod works sort of
#pod
#pod use Sub::Replace;
#pod
#pod my $_OLD_SUBS;
#pod BEGIN {
#pod require Foo;
#pod $_OLD_SUBS = Sub::Replace::sub_replace('foo' => \&Foo::foo);
#pod }
#pod
#pod UNITCHECK {
#pod Sub::Replace::sub_replace($_OLD_SUBS);
#pod }
#pod
#pod That means:
#pod
#pod =over 4
#pod
#pod =item *
#pod
#pod Imported subroutines are installed into the caller namespace at compile time.
#pod
#pod =item *
#pod
#pod Imported subroutines are cleaned up just after the unit which defined
#pod them has been compiled.
#pod
#pod =back
#pod
#pod See L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >> for
#pod the concept of "compilation unit" which is relevant here.
#pod
#pod See L<Sub::Replace> for a few gotchas about why this is not simply done
#pod with Perl statements such as
#pod
#pod *foo = \&Foo::foo;
#pod
#pod =head1 DEBUGGING
#pod
#pod You can set the C<IMPORTER_ZIM_DEBUG> environment variable
#pod for get some diagnostics information printed to C<STDERR>.
#pod
#pod IMPORTER_ZIM_DEBUG=1
#pod
#pod =head1 SEE ALSO
#pod
#pod L<Importer::Zim>
#pod
#pod L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >>
#pod
#pod L<Importer::Zim::Lexical>
#pod
#pod L<Importer::Zim::EndOfScope>
#pod
#pod =cut
__END__
=pod
lib/Importer/Zim/Unit.pm view on Meta::CPAN
177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235works
sort
of
my
$_OLD_SUBS
;
BEGIN {
$_OLD_SUBS
= Sub::Replace::sub_replace(
'foo'
=> \
&Foo::foo
);
}
UNITCHECK {
Sub::Replace::sub_replace(
$_OLD_SUBS
);
}
That means:
=over 4
=item *
Imported subroutines are installed into the caller namespace at compile time.
=item *
Imported subroutines are cleaned up just after the unit which defined
them has been compiled.
=back
See L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >> for
the concept of "compilation unit" which is relevant here.
See L<Sub::Replace> for a few gotchas about why this is not simply done
with Perl statements such as
*foo = \&Foo::foo;
=head1 DEBUGGING
You can set the C<IMPORTER_ZIM_DEBUG> environment variable
for get some diagnostics information printed to C<STDERR>.
IMPORTER_ZIM_DEBUG=1
=head1 SEE ALSO
L<Importer::Zim>
L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >>
L<Importer::Zim::Lexical>
L<Importer::Zim::EndOfScope>
=head1 AUTHOR
Adriano Ferreira <ferreira@cpan.org>
=head1 COPYRIGHT AND LICENSE
t/02-basic.t view on Meta::CPAN
891011121314151617181920212223242526272829BEGIN {
our
@EXPORT_OK
=
qw(f1 f2 f3)
; }
sub
f1 { }
sub
f2 { }
sub
f3 { }
sub
f4 { }
package
main;
UNITCHECK {
ok( !__PACKAGE__->can(
'f1'
),
'f1 is gone (by UNITCHECK time)'
);
ok( !__PACKAGE__->can(
'f2'
),
'f2 is gone (by UNITCHECK time)'
);
}
ok(
defined
&f1
,
'f1 was imported'
);
is( \
&f1
, \
&M1::f1
,
'f1 comes from M1'
);
ok(
defined
&f2
,
'f2 was imported'
);
is( \
&f2
, \
&M1::f2
,
'f2 comes from M1'
);
( run in 0.317 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )