Hello Monks,
I am trying to create my first module for CPAN and I got stack to a very minor problem, that I can not figure out how to proceed.
I have a module with name Net::SNTP::Client, sample provided bellow:
#!/usr/bin/perl use strict; use warnings; use Exporter qw(import); package Net::SNTP::Client; our $VERSION = v5.18.2; # Or higher... our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = qw(func1 func2); our %EXPORT_TAGS = ( # Mappings for :shortcuts. DEFAULT => [ qw(&func1) ], BOTH => [ qw(&func1 &func2) ] ); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } 1;
I can not figure out how to call the module from a script, sample provided bellow:
#!/usr/bin/perl use strict; use warnings; BEGIN { push @INC, '/home/username/Desktop/' } use Net::SNTP::Client; my @list = qw (J u s t ~ A n o t h e r ~ P e r l ~ H a c k e r !); # case 1 # use Net::SNTP::Client; # print func1(@list),"\n"; # print func2(@list),"\n"; # case 2 # use Net::SNTP::Client qw(&func1); # print func1(@list),"\n"; # print MyModule::func2(@list),"\n"; # case 3 # use Net::SNTP::Client qw(:DEFAULT); # print func1(@list),"\n"; # print func2(@list),"\n"; # case 4 # use Net::SNTP::Client qw(:Both); # print func1(@list),"\n"; # print func2(@list),"\n";
I keep getting the error:
an't locate Net/SNTP/Client.pm in @INC (you may need to install the Ne +t::SNTP::Client module) (@INC contains: /etc/perl /usr/local/lib/perl +/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 +/usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl . /h +ome/username/Desktop/) at client.pl line 8. BEGIN failed--compilation aborted at client.pl line 8.
I am following Simple Module Tutorial and trying to convert my module with defined classes to a reusable module and I can not figure it out where I am going wrong. I have spend 3 hours reading online and trying I still nothing. I know it is something so small but I can not understand why it can not work.
Update: I found how to install the module on my pc based on the instructions from Create a CPAN-style Perl module.
Thank you in advance for your time and effort.
In reply to How to create a reusable module with Exporter [SOLVED] by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |