Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Templates for Perl Programs and Perl Modules

by toma (Vicar)
on Jan 21, 2003 at 05:23 UTC ( #228590=perlmeditation: print w/replies, xml ) Need Help??

I have released two new perl template generators. These programs create the basic structure of a new module or program. This saves typing and makes it easier to get started.

The program for modules is similar to the results of h2xs -aXn, but it does not create Makefile.PL or the rest of the nice framework created by h2xs.

I use my program in conjunction with h2xs, replacing the file module_name.pm with the output from my program.

I welcome comments on the code and ideas for enhancements.
Update: Thanks to PodMaster for providing enhancement suggestions.
Update: Updated the code to fix the Win32 problem.

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re: Templates for Perl Programs and Perl Modules
by vagnerr (Prior) on Jan 21, 2003 at 08:57 UTC
    Looks interesting and potentialy usefull. Up till now I have just used vi(m)'s ability to use a template file when you edit a new file. Putiing the following in the .vimrc
    "load up skeleton files where needed autocmd BufNewFile *.pm 0r ~/.vim/skeleton.pm autocmd BufNewFile *.pl 0r ~/.vim/skeleton.pl
    However I will give serious consideration to trying your scripts.

    _______________________________________________________
    Remember that amateurs built Noah's Ark. Professionals built the Titanic.
Re: Templates for Perl Programs and Perl Modules
by gjb (Vicar) on Jan 21, 2003 at 08:38 UTC

    Nice and useful idea, but it doesn't run under ActiveState Perl 5.6.1 build 633 (Windows NT). It reports the following error:

    Uncaught exception from user code: POSIX::cuserid not implemented on this architecture at ./perl_template.pl line 11.
    Thought you might want to know this, -gjb-

      I'll fix this today when I get access to a Windows box. Meanwhile, if you want to try the program, you can just hardcode the value of $author by changing:
      my $userid= POSIX::cuserid(); my $author = (getpwnam($userid))[6];
      to
      my $author = "Your Name Here";

      The trick for getting the 'real name' of a user on unix uses the user id with cuserid() and the corresponding entry in /etc/passwd with getpwnam(). It will be interesting to figure out how to get this information from a Windows box.

      Thanks!

      It should work perfectly the first time! - toma

Re: Templates for Perl Programs and Perl Modules
by toadi (Chaplain) on Jan 21, 2003 at 13:34 UTC
    Well I have almost the same. In my vim config files. It even automatically gives CVS $Id$, last modified, author, ...
    It even recognize which type of file: .sh, .pl, .c, ... And wil do the correct templating for that kind of file.
    Works very good. Think most people automate this kind of stuff.

    --
    My opinions may have changed,
    but not the fact that I am right

      I wonder if there is a way to automatically detect if a user is using CVS, RCS, ClearCase, etc. If so, I could add the appropriate line in the file. Another approach might be to try to read vim's configuration file, or I could use a configuration file custom for this application.

      For this type of easy program it doesn't matter much if you code it in vim or Perl. If I had found a template in vim I might not have written this at all. I would like to see what you use, or get a pointer to a repository of good vim templates. There is a lot of content at http://www.vim.org, and I don't know where the good templates are.

      It should work perfectly the first time! - toma

        I don't know if you've already realized this, but, if the file is in a directory that has a CVS directory you could assume CVS.

        Harley J Pig
Re: Templates for Perl Programs and Perl Modules
by Heidegger (Hermit) on Jan 21, 2003 at 14:50 UTC
    As someone already mentioned earlier, this script doesn't work on Windows platforms (POSIX::cuserid).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://228590]
Approved by PodMaster
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-12-03 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (29 votes). Check out past polls.

    Notices?