Skip to content

Commit c6b972b

Browse files
committed
allow magic to be avoided
1 parent ae792f6 commit c6b972b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/Object/Util.pm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package Object::Util;
99
our $AUTHORITY = 'cpan:TOBYINK';
1010
our $VERSION = '0.004';
1111

12-
use Carp qw( croak );
12+
use Carp qw( carp croak );
1313
use List::Util 1.29 qw( pairkeys pairvalues );
1414
use Scalar::Util 1.23 qw( blessed reftype );
1515

@@ -365,16 +365,26 @@ sub setup_for :method
365365
sub import :method
366366
{
367367
my $me = shift;
368+
my (%args) = @_;
368369
my ($caller, $file) = caller;
369370

370-
if ($file ne '-e' and eval { require B::Hooks::Parser })
371+
$args{magic} = "auto" unless defined $args{magic};
372+
373+
if ($file ne '-e'
374+
and $args{magic}
375+
and eval { require B::Hooks::Parser })
371376
{
372377
my $varlist = join ',', $me->sub_names;
373378
my $reflist = join ',', map "\\$_", $me->sub_names;
374379
B::Hooks::Parser::inject(";my($varlist);$me\->setup_for($reflist);");
375380
return;
376381
}
377382

383+
if ($args{magic} and $args{magic} ne "auto")
384+
{
385+
carp "Object::Util could not use magic; continuing regardless";
386+
}
387+
378388
my %subs = $me->subs;
379389
for my $sub_name (sort keys %subs)
380390
{
@@ -626,6 +636,11 @@ version of Perl, or your Perl is too old to have Internals::SvREADONLY,
626636
then it has various fallback routes, but the variables it provides may
627637
end up as package (C<our>) variables, or not be read-only.
628638
639+
If the magic works on your version of Perl, but you wish to avoid the
640+
magic anyway, you can switch it off:
641+
642+
use Object::Util magic => 0;
643+
629644
=head1 BUGS
630645
631646
Please report any bugs to

0 commit comments

Comments
 (0)