Real World Example


This example is an implementation of a batch command language that uses the Perl intepreter to provide syntax checking and additional functionality of batch variables, loops, input, output, etc.

The commands provided are functions for provisioning LNP data and for setting flags for the command processing.


Code

  1   sub do_batch_file
  2   {
  3       my ($batch_file) = @_;
  4
  5       my $cpt = new Safe;
  6
  7       $cpt->share (qw(
  8           &dlt_lnp_lrn 
  9           &dlt_lnp_npanxx   
 10           &dlt_lnp_sub 
 11           &dlt_split_npa
 12           &rtrv_lnp_sub
 13           &set_cont_wo_remote 
 14          &set_debug 
 15          &upd_lnp_lrn 
 16          &upd_lnp_npanxx
 17          &upd_lnp_sub
 18          &upd_split_npa
 19          ));
 20
 21       $cpt->share_from ('main', [qw(
 22           *IO::
 23           *SelectSaver::
 24           *STDOUT
 25           )]);
 26
 27       print "\n";
 28
 29       # Turn on batch mode
 30       set_batch_mode (1);
 31
 32       # Save current debug value in order to restore after batch
 33       my $save_debug = $Debug;
 34       
 35       my $return = $cpt->rdo ($batch_file);
 36       if ($return)
 37       {
 38           print "Done.\n";
 39       }
 40       elsif ($@)
 41       { 
 42           warn "Batch Error: $@";
 43       }
 44       elsif (not defined $return)
 45       {
 46           warn "Could not do $batch_file: $!\n";
 47       }
 48       else
 49       {
 50           warn "Exit value from $batch_file was FALSE.\n";
 51       }
 52
 53       # Restore debugging value in case batch changed it
 54       set_debug ($save_debug);
 55
 56       # Turn off continue without remote in case batch turned it on
 57       set_cont_wo_remote (0);
 58
 59       # Turn off batch mode
 60       set_batch_mode (0);
 61
 62   } # do_batch_file


Discussion

Line: