I am playing around with a existing perl module lets call it Obj. I have added some new features (subroutines / methods) to Obj but store them in another .pm call it Foo. However I dont want Obj to inherit every sub from Foo.
Now I have been reading perl documentation for a few hours and am confused. https://perldoc.perl.org/Exporter#Selecting-What-to-Export Just says 'Do not export method names!'
Here is some example code, I'd like to not see sub _not_exported from Obj.pm:
#!/usr/bin/env perl
use strict;
use warnings;
use diagnostics;
package Foo;# Foo is a new PM file used to extend Obj with collections of subroutine's.
# I want to use hello() from Obj
#use Exporter 'import';
use Exporter qw(import);
our @EXPORT_OK = qw/hello/;
sub hello {
my $self = shift;
$self->{test} = 'Hello world';
}
# I'd rather not pollute Obj with this sub
# or perfreably all subs the begin with a underscore
# How do I exclude this sub?
sub _not_exported {
my $self = shift;
return 'Exported';
}
#main old code object module
package Obj; # large old PM file I dont want to change this file much
# pull in the new module
use base 'Foo';
# use base seems better than this:
#import Foo;
#our @ISA = qw(Foo);
sub new {
my $self = {};
bless $self, 'Obj';
return $self;
}
eval { $this = $form->_not_exported() } ; #Should return nothing
sub catch_hash {
my ($self,$arg) = @_;
$arg |= '';
$self->{test} = 'catch';
}
#Perl script, creates an object using Obj;
package main;
#use Obj;
import Obj;
my $form = Obj->new();
$form->catch_hash();
print "Toss? '$form->{test}' \n";
$form->hello();
print "\nHello? '$form->{test}'\n";
my $this = "";
eval { $this = $form->_not_exported() } ; #Should return nothing
print "$this\ndone\n";
1;
I am open to other options like Moo / Moose but dont want to change the old code much. Thanks in advance