This page (revision-3) was last changed on 21-Jan-2008 13:17 by ThomasBayen 

This page was created on 24-Jul-2007 16:27 by MarkusMonderkamp

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
3 21-Jan-2008 13:17 1 KB ThomasBayen to previous Tagging
2 24-Jul-2007 16:32 1 KB MarkusMonderkamp to previous | to last Sentinel Modul
1 24-Jul-2007 16:27 1 KB MarkusMonderkamp to last Sentinel Modul

Page References

Incoming links Outgoing links

Version management

Difference between version and

!!Sentinel Perl Modul

Wie kann ich einem Executable Bewusstsein darüber geben, ob es auf der Konsole, als Klasseninstanz oder im Webkontext aufgerufen wurde?

Nachdem Jens am 23.07.2007 den naheliegenden Vorschlag gemacht hatte, gaben mir die [Perlmonk-Klostermauern|http://perlmonks.org/?node_id=621378] und etwas CGI-Environment Recherche die Steilvorlage für folgenden Modul-Prototyp/Erlkönig ''sentinel.pm'':

{{{
#!/usr/bin/perl
#
# sentinel.pm - Code that recognizes the caller: console, class or web-environment
#
# M.M. - 20070724
#
package Runnable;
use vars qw/ $key $value/;

# man perlform(1)
format STDOUT =
| ENV @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
$key, $value
.

###############
sub do_script {
###############
  print "called from Console or Terminal\n", "=" x 31, "\n";
  foreach $key (sort keys %ENV) {
       $value = $ENV{ $key };
       # nutze Perlformatvariable mit write auf Konsole - s.o. und man perlform(1)
       write;
  }
  exit 0;
}

############
sub do_cgi {
############
  use CGI qw/:standard *table/;

  print header, start_html("CGI-Testskript zur Identifizierung des Aufrufers");
  print start_table({border=>"1"});
  foreach $key (sort keys %ENV) {
       printf "<tr><td>%s</td><td>%s</td></tr>", $key, $ENV{ $key };
  }
  print end_table();
  exit 0;
}

__PACKAGE__->do_cgi if defined $ENV{"HTTP_HOST"};
__PACKAGE__->do_script unless caller;

############################################
printf "Instance: Called from %s\n", caller;
############################################


1;

}}}
24.07.2007 - MarkusMonderkamp

[{Tag Perl}]