adur has asked for the wisdom of the Perl Monks concerning the following question:

I've followed the various tutorials, and have followed the instructions on Module::Starter, but can't make a working module. I'm pretty new to Perl and I'm not a real programmer. Basically, I'm making a Bioperl module. It's supposed to be in the package Bio::DB::CCDS. It has a few global variables and doesn't use a "$self" variable. Does it need to? I'm trying to use a few global variables instead. The Bio directory and DB directory already exist. I'm using Exporter like this:
use Exporter; use vars qw($VERSION @ISA @EXPORT); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw(new Get_CCDS_IDs Get_gene gene_coordinates Get_exons + Write_ccds Get_strand Gene_id Gene_count);
Should @EXPORT use qw? Should each function named in it have a & sign before it? How do I create a working module and put it in the correct directory? How would I have to modify the Makefile? I'm using ubuntu. Thank you for your help.

Replies are listed 'Best First'.
Re: I really need help making a module.
by 1nickt (Canon) on Aug 19, 2015 at 04:20 UTC
Re: I really need help making a module.
by james28909 (Deacon) on Aug 19, 2015 at 03:55 UTC
    I think you need to declare the package name at the top like:
    package Your::Package;
    Make sue they are in the appropriate directories too.

    This is what i have at the top of my modules:

    package My::Module; use Exporter qw(import); @EXPORT_OK = qw(sub names here);

    An example:

    package My::Package; use Exporter qw(import); @EXPORT_OK = qw(print_lines); use strict; use warnings; sub print_lines{ my ($input) = @_; while(my $lines = <$input>){ print $lines; } }

    And call it from you script like:

    use strict; use warnings; use My::Package qw(print_lines); open my $file, '<', shift; print_lines($file);
      I have it at the top, but I tried putting it in the appropriate directory, and it wasn't recognized. I tried using module-starter, but it didn't give me an option to put it into Bio::DB. It tried to erase and replace those directories.
Re: I really need help making a module.
by Anonymous Monk on Aug 19, 2015 at 04:03 UTC

    Basically, I'm making a Bioperl module. It's supposed to be in the package Bio::DB::CCDS. It has a few global variables and doesn't use a "$self" variable. Does it need to?

    Probably. You've decided it goes into "Bio::DB" so it should follow the conventions/interface of the existing project

    Should @EXPORT use qw?

    Thats not the question to ask, the question is should you export anything (the answer is no)

    Should each function named in it have a & sign before it?

    If you still think its important to know, Exporter answers it

    How do I create a working module and put it in the correct directory? How would I have to modify the Makefile?

    You start with module-starter, then you install the module. A Guide to Installing Modules

    In between you probalby want to copy/paste some ideas from one of the Bio::DB:: modules, say Bio::DB::Fasta. You'll notice it has "$self" and doesn't use Exporter.

    zentara package/module tutorial

      From what I see, I seems like @EXPORT makes methods in the module available for use, but without having to reference the module, meaning this - $blah->somemethod - wouldn't be necessary. So, I'll remove this, thank you. I've never used & and it's never given me problems. I used module-starter and it didn't give me an option to put it in the correct directory. It tried to erase Bio::DB. I'll try again with your link. It installed a file to usr/local/man/man3 that isn't perl code. What is it? I was trying to install it in usr/share/perl5/Bio/DB/. Bio::DB::Fasta uses another module as a base and from what I see, it seems like $self is only used when parent methods are called. I'm not really using anything as a base except for Exporter, so I'm guessing that if I use $self, it will just be an Exporter object. What if I don't use exporter? Is $self required for it to work? I spent an hour looking for a module that doesn't use any other module and also uses arguments, but couldn't find any. Do I need to use $self to use other methods within the module?

        From what I see, I seems like @EXPORT makes methods in the module available for use, but without having to reference the module, meaning this - $blah->somemethod - wouldn't be necessary. So, I'll remove this, thank you.

        I've never used & and it's never given me problems.

        I used module-starter and it didn't give me an option to put it in the correct directory. It tried to erase Bio::DB. I'll try again with your link. It installed a file to usr/local/man/man3 that isn't perl code. What is it? I was trying to install it in usr/share/perl5/Bio/DB/.

        Bio::DB::Fasta uses another module as a base and from what I see, it seems like $self is only used when parent methods are called. I'm not really using anything as a base except for Exporter, so I'm guessing that if I use $self, it will just be an Exporter object. What if I don't use exporter?

        Is $self required for it to work? I spent an hour looking for a module that doesn't use any other module and also uses arguments, but couldn't find any. Do I need to use $self to use other methods within the module? And can I include global variables in the module? I have two hashes and a scalar at the top.

Re: I really need help making a module.
by GotToBTru (Prior) on Aug 20, 2015 at 12:38 UTC

    What do you mean by "isn't working"? Does the module fail to compile? What errors do you get when you try to use it?

    Dum Spiro Spero