My previous question has solved my problem, but left me with a lack of understanding.
use 5.014;
use warnings;
use Test::More;
# still has carp after no Carp
package Test0 {
use Carp qw( carp );
sub new {
my $class = shift;
my $self = {};
carp 'good';
bless $self, $class;
return $self;
}
no Carp;
}
my $t0 = Test0->new;
ok( ! $t0->can('carp'), 'cannot carp');
This test does not pass, which means no ... doesn’t do what I think it does, which includes unimporting the symbols. I’ve read perldoc no, but it really seems to be rather unenlightening. Given the results of this code I’d say that it doesn’t exactly do what it advertises.
What does no do? When and why should I be using it?
nocalls a package’sunimport(), whereasusecallsimport(), both silently skipping the case where no desired sub is found.However, few packages — indeed, mostly only the pragma modules — support
unimport().