log errors for nadmin.pl/nuser.pl when the controlled fails to load
[bse.git] / site / cgi-bin / modules / BSE / UI / NUser.pm
CommitLineData
0eb78304
TC
1package BSE::UI::NUser;
2use strict;
3use base 'BSE::UI::Dispatch';
4
b08807f3 5our $VERSION = "1.001";
cb7fd78d 6
4c4d3c3f
TC
7sub controller_section {
8 'nuser controllers';
9}
10
0eb78304
TC
11sub dispatch {
12 my ($class, $req) = @_;
13
14 my $controller_id = $req->cgi->param('_p');
15 my ($action, $rest);
16 unless ($controller_id) {
17 my @components = split '/', $ENV{PATH_INFO}, -1;
18 shift @components if @components && $components[0] eq '';
19 my @rest;
20 ($controller_id, $action, @rest) = @components;
21 $rest = join '/', @rest;
22 }
23
4c4d3c3f
TC
24 my $section = $class->controller_section;
25 $controller_id ||= $req->cfg->entry($section, 'default');
0eb78304
TC
26 $controller_id
27 or return $class->error($req, "No controller found in path");
28
29 my $controller_class =
4c4d3c3f 30 $req->cfg->entry($section, $controller_id)
0eb78304 31 or return $class->error($req, "No class found for controller $controller_id");
4c4d3c3f 32
0eb78304
TC
33 (my $controller_file = $controller_class . ".pm") =~ s!::!/!g;
34 eval {
4c4d3c3f
TC
35 local @INC = @INC;
36 my $local_inc = $req->cfg->entry('paths', 'libraries');
37 unshift @INC, $local_inc if $local_inc;
38
0eb78304
TC
39 require $controller_file;
40 };
41 if ($@) {
b08807f3
TC
42 my $error = $@;
43 print STDERR "Error loading controller $controller_file: $error\n";
44 eval {
45 require BSE::TB::AuditLog;
46 BSE::TB::AuditLog->log
47 (
48 component => "nadmin::load",
49 level => "critical",
50 actor => "S",
51 msg => "Failed to load module $controller_class",
52 dump => <<EOS
53Class: $controller_class
54File: $controller_file
55Error: $error
56EOS
57 );
58 };
0eb78304
TC
59 return $class->error($req, "Internal error: Could not load controller class");
60 }
61 my %opts;
62 $action and $opts{action} = $action;
63 defined $rest or $rest = '';
64 $opts{rest} = $rest;
65 $opts{controller_id} = $controller_id;
66 my $controller = $controller_class->new(%opts);
67
68 return $controller->dispatch($req);
69}
70
711;
72
73__END__
74
75=head1 NAME
76
77BSE::UI::NUser - dispatcher for user side functionality.
78
79=cut