Templates (again)

grrraham
2004-09-17
2013-05-20
  • grrraham
    grrraham
    2004-09-17

    It's been 10 months since the question was last asked.  Could anybody reply with a c&p of their templates? 
    While it may seem trivial, knowing what works for somebody else would be a great head-start. 
    It really does not matter if they are not perfect.

     
    • Ivan Wills
      Ivan Wills
      2004-10-26

      Here are the templates I use. I tend to use them to write standard sub's and basic file layouts.

      Hope this helps

      Ivan

      <?xml version="1.0" encoding="UTF-8"?>
      <templates><template name="for" description="C style for loop" context="perl" enabled="true">for ( ${cursor}; ; )
      {
          ;
      }</template><template name="foreach" description="Loop over an array" context="perl" enabled="true">foreach my $$item (@array)
      {
          ${cursor};
      }</template><template name="pod doxygen like" description="A pod comment with doxygen like constructs" context="perl" enabled="true">=head2 function ( ${cursor}$$parameter_list )

          @param    $$param1:    description
          @param    :   
          @return    type:        return values

      Long description

      =cut</template><template name="while" description="while loop" context="perl" enabled="true">while ( ${cursor} )
      {
          ;
      }</template><template name="if" description="An if block" context="perl" enabled="true">if ( ${cursor} )
      {
          ;
      }</template><template name="if ... else" description="if then else statement" context="perl" enabled="true">if ( ${cursor} )
      {
          ;
      }
      else
      {
          ;
      }</template><template name="sub" description="Generate a subroutine with a pod comment headder" context="perl" enabled="true">=head2 function ( $$param )

          @param    $$param:    description
          @return    type:        return description

      Long description

      =cut

      sub function
      {
          ${cursor};
      }</template><template name="package" description="Creates a new package" context="perl" enabled="true">package Q;

      =head1 NAME

      Q

      =head1 SYNOPSIS

      # include the module

      use Q;

      # create a new Q object

      my $$q = new Q();

      # do something

      $$q-&gt;func();

      =head1 DESCRIPTION

      what it does

      =cut

      use strict;
      use Exporter;
      use Data::Dumper qw/Dumper/;
      use Carp;
      use CGI;
      use DBI;
      use base qw/Exporter/;

      our $$VERSION = 0.1;
      our @EXPORT = qw//;
      our @EXPORT_OK = qw//;

      =head1 FUNCTIONS

      =cut

      =head2 new ( $$param )

          @param    $$param:    description
          @return    Q:        return a new Q object

      Create a new Q object

      =cut

      sub new
      {
          my $$caller = shift;
          my $$class = (ref $$caller) ? ref $$caller : $$caller;
          my $$self = {};
          ${cursor};
          bless $$self, $$class;
      }

      1;

      =head1 ALSO SEE

      Apollo::

      =head1 AUTHORS and COPYRIGHT

      Ivan Wills

      Copyright ${year} Apollo Life Sciences Pty. Ltd.

      =cut

      __END__</template><template name="sub" description="An object method sub" context="perl" enabled="true">=head2 method ( $$param )

          @param    $$param:    description
          @return    type:        return description

      Long description

      =cut

      sub method
      {
          my $$self = shift;
          ${cursor}#my $$dbh = $$self-&gt;{-dbh};
          #my $$q = $$self-&gt;{-cgi};
         
      }</template><template name="do" description="A do while loop" context="perl" enabled="true">do
      {
          ;
      }
      while ( ${cursor} )</template><template name="unless" description="An inline unless" context="perl" enabled="true">unless ( ${cursor} );</template><template name="if" description="Inline if" context="perl" enabled="true">if ( ${cursor} );</template><template name="sub" description="A class method sub" context="perl" enabled="true">=head2 class_method ( $$param )

          @param    $$param:    description
          @return    type:        return description

      Long description

      =cut

      sub class_method
      {
          my $$caller = shift;
          my $$class = (ref $$caller) ? ref $$caller : $$caller;
          ${cursor}
      }</template><template name="elsif" description="The else if block" context="perl" enabled="true">elsif ( ${cursor} )
      {
          ;
      }</template><template name="else" description="An else block" context="perl" enabled="true">else
      {
          ${cursor};
      }</template><template name="unless" description="An unless block" context="perl" enabled="true">unless ( ${cursor} )
      {
          ;
      }</template><template name="find files" description="A function that recursivly searches for files" context="perl" enabled="true">sub find_files
      {
          my ($$directory, $$search) = @_;
         
          opendir DIR, $$directory or warn "Unable to open $$directory: $$!\n" and return;
          my @files = readdir DIR;
          close DIR;
         
          foreach my $$file (@files)
          {
              next if $$file =~ /^\.\.?$$/;    # ignore the directories . and ..
              if ( -d "$$directory/$$file" )
              {
                  # recurse to sub directories
                  find_files( "$$directory/$$file", $$search );
              }
              else
              {
                  # process the file
                  ${cursor};
              }
          }
          return ;
      }</template><template name="perl" description="Create a new cgi file" context="perl" enabled="true">#!/usr/bin/perl -wT

      ## MENU ('Top Level Menu/Sub Menu/Menu item', 'System/Something/*', -display =&gt; 1, )

      use strict;
      use warnings;
      use CGI;
      use Apollo::System::Session;
      use Apollo::System::HTML;

      ### creating CGI object
      my $$q = new CGI;

      my $$session_valid = 0;
      my $$session = new Apollo::System::Session;
      my $$html = new Apollo::System::HTML( -session =&gt; $$session, -cgi =&gt; $$q, -style =&gt; 'Main' );

      if ( my $$text = $$html-&gt;start_session( "System/Something/*" ) )
      {
          print $$text;
          exit;
      }

      print $$q-&gt;header( -type =&gt; "text/html" ),
              $$html-&gt;start_page( { -title =&gt; "Welcome to ALS" } ),
              $$html-&gt;top_of_page( { -heading =&gt; "Start Page" } );
      #
      #
      #    START YOUR CODE

      ${cursor}

      #    END OF YOUR CODE
      #
      #

      print $$html-&gt;bottom_of_page(),
              $$q-&gt;end_html();

      exit;

      __END__</template><template name="warn" description="Database error warnning" context="perl" enabled="true">warn "${cursor}: $$DBI::errstr" if defined $$DBI::errstr;</template><template name="warn" description="Long database error warning" context="perl" enabled="true">if ( defined $$DBI::errstr )
      {
          warn "${cursor}: $$DBI::errstr";
      }</template><template name="perl" description="A simple perl program" context="perl" enabled="true">#!/usr/bin/perl

      use strict;

      __DATA__</template><template name="perl" description="A comand line perl program" context="perl" enabled="true">#!/usr/bin/perl

      use strict;
      use Getopt::Long;

      unless ( @ARGV )
      {
          help();
          exit();
      }

      process_options();
      exit();

      sub process_options
      {
          my ( $$other, $$help, $$verbose ) = ( '', 0, 0 );
          GetOptions(
                      'other=s'    =&gt;    \$$other,
                      'verbose!'    =&gt;    \$$verbose,
                      help        =&gt;    \$$help,
                    );
          if ( $$help )
          {
              help();
              exit();
          }
          # do stuff here
      }

      sub help
      {
          print &lt;&lt;HELP;

      Usage: script.pl [options]
        -o --other     Other
        -h --help      Show this file
        -v --verbose   Show more detailed output

      Note: stuff

      HELP
      }

      __DATA__</template><template name="perl" description="Test module" context="perl" enabled="true">#!/usr/bin/perl

      use strict;
      use Apollo::Test;
      use Apollo::Module;

      my $$t = new Apollo::Test();

      test_example($$t);

      $$t-&gt;display();
      exit();

      sub test_example
      {
          my ( $$t, ) = @_;
          $$t-&gt;test( "" );
          # do test
          my $$r;
          $$t-&gt;result( "", $$r );
      }

      __DATA__</template></templates>