++ed by:
SSCAFFIDI

1 PAUSE user(s)
1 non-PAUSE user(s).

Stephen Nelson

NAME

Devel::Main - Syntactic sugar for a script's main routine

VERSION

version 0.005

SYNOPSIS

  use Devel::Main 'main';
  
  main {
    # Your main routine goes here
  };

DESCRIPTION

This module provides a clean way of specifying your script's main routine.

METHODS

main()

Declares your script's main routine. Exits when done.

If, instead of executing your script, you load it with use or require, main creates a subroutine named run_main in the current package. You can then call this subroutine to run your main routine. Arguments passed to this subroutine will override @ARGV.

Example:

  require './my_script.pl';
  
  run_main( 'foo' );  # Calls the main routine with @ARGV = ('foo')

If you alias the 'main' routine to another name, the "run" method will also be aliased. For example, if 'my_script.pl' had said:

  use Devel::Main main => { -as => 'primary' };
  
  primary {
    # Main code here
  };

then the installed subroutine would be called 'run_primary'.

You can also control whether or not the script exits after the main routine via the import parameter 'exit'.

   use Devel::Main 'main' => { 'exit' => 0 };
   
   main {
     # Main routine
   };
   print "Still running\n";

Finally, you can change the name of the subroutine to call the main routine via the import parameter 'run_sub_name'.

   # In 'my_script.pl'
   use Devel::Main 'main' => { 'run_sub_name' => 'run_the_main_routine' };
   
   # In other (test?) script
   require './my_script.pl';
   
   run_the_main_routine('bar'); # Calls the main routine with @ARGV = ('bar');

METHODS

CREDITS

This module was inspired by brian d foy's article Five Ways to Improve Your Perl Programming.

AUTHOR

Stephen Nelson <stephenenelson@mac.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Stephen Nelson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.




Hosting generously
sponsored by Bytemark