Search code examples
perlperl-exporter

Perl Export Suggestions


I am working with a new program that needs to interface with perl.

The example code suggests that all of the methods will be exported to the global namespace like below:

use BGPmon::Fetch;
my $ret = init_bgpdata();
my $ret = connect_bgpdata();
my $xml_msg = read_xml_message();
...

However using any of the methods like that causes "Undefined subroutine &Fetch::init_bgpdata." I know the module works but doesn't seem to be exporting correctly because I can still use the long names: BGPmon::Fetch::init_bgpdata();.

Any reason why the module isn't exporting correctly?

Note: I would love to share the method code but I know its not a problem with the module. It is part of a codeset I can't share and I know it works because the tests manage to pass.

Exporter Section

require Exporter;
our $AUTOLOAD;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(connect_bgpdata read_xml_message
  close_connection is_connected messages_read uptime connection_endtime
  get_error_code get_error_message get_error_msg) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

Public source code (mine is the dev)


Solution

  • In the code you have given, you are defining a tag :all

    So you calling code can do

    use  BGPmon::Fetch ':all' ;
    

    Alternatively you can import them individually

    use BGPmon::Fetch qw(init_bgpdata connect_bgpdata); # and so on
    

    It is worth having a look at Exporter - apologies if already done so