| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | |
|---|
| 5 | BEGIN { |
|---|
| 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 | |
|---|
| 12 | use lib 'lib'; |
|---|
| 13 | use DJabberd; |
|---|
| 14 | use Getopt::Long; |
|---|
| 15 | use FindBin qw($Bin); |
|---|
| 16 | use vars qw($DEBUG); |
|---|
| 17 | BEGIN { |
|---|
| 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 | |
|---|
| 34 | my ($daemonize); |
|---|
| 35 | |
|---|
| 36 | my $conffile; |
|---|
| 37 | |
|---|
| 38 | Getopt::Long::GetOptions( |
|---|
| 39 | 'd|daemon' => \$daemonize, |
|---|
| 40 | 'debug=i' => \$DEBUG, |
|---|
| 41 | 'conffile=s' => \$conffile, |
|---|
| 42 | ); |
|---|
| 43 | |
|---|
| 44 | my $server = DJabberd->new( |
|---|
| 45 | daemonize => $daemonize |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | my @try_conf = ( $conffile, "/etc/djabberd/djabberd.conf", "djabberd.conf" ); |
|---|
| 49 | shift @try_conf while @try_conf && ! -e $try_conf[0]; |
|---|
| 50 | die "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 | |
|---|
| 56 | package DB; |
|---|
| 57 | no strict 'refs'; |
|---|
| 58 | no utf8; |
|---|
| 59 | |
|---|
| 60 | sub DB{}; |
|---|
| 61 | sub 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 | } |
|---|