root/tags/DJabberd-0.83/djabberd

Revision 745, 2.3 kB (checked in by plindner, 3 years ago)

use strict/warnings before everything else

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5BEGIN {
6    # tell debugger of sub enter/exit,
7    $^P |= 0x01  if     $ENV{TRACE_DJABBERD};
8    # keep descriptive string value of all anon subs maintained per coderef:
9    $^P |= 0x200 unless $ENV{NDEBUG_SUB_NAMES};
10};
11
12use lib 'lib';
13use DJabberd;
14use Getopt::Long;
15use FindBin qw($Bin);
16use vars qw($DEBUG);
17BEGIN {
18    # while the core ("use DJabberd" above) must be in normal paths,
19    # we open up the lib paths here, so make it easy to work in
20    # the subversion directories and have cousin plugins in their
21    # dev locations, but not system-wide installed.
22    if (-e "$Bin/Makefile.PL") {  # lame check to see if we're in dev directory
23        opendir(my $dh, "$Bin/../");
24        foreach my $d (grep { /^DJabberd-/ } readdir($dh)) {
25            my $dir = "$Bin/../$d/lib";
26            next unless -d $dir;
27            unshift(@INC, $dir);
28        }
29    }
30}
31
32$DEBUG = 0;
33
34my ($daemonize);
35
36my $conffile;
37
38Getopt::Long::GetOptions(
39                         'd|daemon'     => \$daemonize,
40                         'debug=i'      => \$DEBUG,
41                         'conffile=s'   => \$conffile,
42                         );
43
44my $server = DJabberd->new(
45                           daemonize => $daemonize
46                           );
47
48my @try_conf = ( $conffile, "/etc/djabberd/djabberd.conf", "djabberd.conf" );
49shift @try_conf while @try_conf && ! -e $try_conf[0];
50die "No configuration file found, please specify --conffile argument.\n" unless @try_conf;
51
52$server->load_config($try_conf[0]);
53
54$server->run;
55
56package DB;
57no strict 'refs';
58no utf8;
59
60sub DB{};
61sub sub {
62    # localize CALL_DEPTH so that we don't need to decrement it after the sub
63    # is called
64    local $DB::CALL_DEPTH = $DB::CALL_DEPTH+1;
65    #my @foo = @_;
66    my $fileline = "";
67    if (ref $DB::sub eq "CODE") {
68        my @caller = caller;
69        my $pkg = $caller[0];
70        my $line = $caller[2];
71        $fileline = " called from $pkg, line $line";
72    }
73    warn ("." x $DB::CALL_DEPTH . " ($DB::CALL_DEPTH) $DB::sub$fileline\n");
74
75    # Call our subroutine. @_ gets passed on for us.
76    # by calling it last, we don't need to worry about "wantarray", etc
77    # by returning it like this, the caller's expectations are conveyed to
78    # the called routine
79    &{$DB::sub};
80}
Note: See TracBrowser for help on using the browser.