| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
############################################################################# |
|
3
|
|
|
|
|
|
|
## $Id: Cmd.pm 6300 2006-05-16 15:25:21Z spadkins $ |
|
4
|
|
|
|
|
|
|
############################################################################# |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package App::Context::Cmd; |
|
7
|
|
|
|
|
|
|
$VERSION = (q$Revision: 6300 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn |
|
8
|
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
25
|
use App; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
116
|
|
|
10
|
5
|
|
|
5
|
|
4978
|
use App::Context; |
|
|
5
|
|
|
|
|
18
|
|
|
|
5
|
|
|
|
|
346
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = ( "App::Context" ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
3382
|
use App::UserAgent; |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
172
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
31
|
use strict; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
6193
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
App::Context::Cmd - context in which we are currently running |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ... official way to get a Context object ... |
|
25
|
|
|
|
|
|
|
use App; |
|
26
|
|
|
|
|
|
|
$context = App->context(); |
|
27
|
|
|
|
|
|
|
$config = $context->config(); # get the configuration |
|
28
|
|
|
|
|
|
|
$config->dispatch_events(); # dispatch events |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# ... alternative way (used internally) ... |
|
31
|
|
|
|
|
|
|
use App::Context::Cmd; |
|
32
|
|
|
|
|
|
|
$context = App::Context::Cmd->new(); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
############################################################################# |
|
37
|
|
|
|
|
|
|
# DESCRIPTION |
|
38
|
|
|
|
|
|
|
############################################################################# |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
A Context class models the environment (aka "context) |
|
43
|
|
|
|
|
|
|
in which the current process is running. |
|
44
|
|
|
|
|
|
|
For the App::Context::Cmd class, this models any of the |
|
45
|
|
|
|
|
|
|
web application runtime environments which employ the Cmd protocol |
|
46
|
|
|
|
|
|
|
and produce HTML pages as output. This includes CGI, mod_perl, FastCGI, |
|
47
|
|
|
|
|
|
|
etc. The difference between these environments is not in the Context |
|
48
|
|
|
|
|
|
|
but in the implementation of the Request and Response objects. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
############################################################################# |
|
53
|
|
|
|
|
|
|
# PROTECTED METHODS |
|
54
|
|
|
|
|
|
|
############################################################################# |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 Methods: |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub dispatch_events_begin { |
|
61
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $options = $self->options(); |
|
64
|
0
|
|
|
|
|
|
my $events = $self->{events}; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if ($#ARGV == -1 || $options->{"?"} || $options->{help}) { |
|
|
|
|
0
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->_print_usage(); |
|
68
|
0
|
|
|
|
|
|
exit(0); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my ($service, $name, $method, $args, $returntype, $contents); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $name_new = 0; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
0
|
|
|
|
$service = $options->{service} || "SessionObject"; |
|
76
|
0
|
0
|
0
|
|
|
|
if ($#ARGV > -1 && $ARGV[0] =~ /^[A-Z]/) { |
|
77
|
0
|
|
|
|
|
|
$service = shift @ARGV; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
0
|
|
|
|
$returntype = $options->{returntype} || "default"; |
|
81
|
0
|
0
|
0
|
|
|
|
if ($#ARGV > -1 && $ARGV[$#ARGV] =~ /^:(.+)/) { |
|
82
|
0
|
|
|
|
|
|
$returntype = $1; |
|
83
|
0
|
|
|
|
|
|
pop(@ARGV); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
$self->{returntype} = $returntype; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
0
|
|
|
|
$name = $options->{name} || "default"; |
|
88
|
0
|
0
|
|
|
|
|
if ($#ARGV > -1) { |
|
89
|
0
|
|
|
|
|
|
$name = shift @ARGV; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
0
|
|
|
|
$method = $options->{method} || "content"; |
|
93
|
0
|
|
|
|
|
|
$method =~ /(.*)/; |
|
94
|
0
|
|
|
|
|
|
$method = $1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if ($#ARGV > -1) { |
|
97
|
0
|
|
|
|
|
|
$method = shift @ARGV; |
|
98
|
0
|
|
|
|
|
|
$args = []; |
|
99
|
0
|
|
|
|
|
|
my ($arg); |
|
100
|
0
|
|
|
|
|
|
while ($#ARGV > -1) { |
|
101
|
0
|
|
|
|
|
|
$arg = shift(@ARGV); |
|
102
|
0
|
0
|
|
|
|
|
if ($arg =~ /^\[(.*)\]$/) { |
|
|
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$contents = $1; |
|
104
|
0
|
0
|
|
|
|
|
if ($arg =~ /\|/) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$arg = [ split(/ *\| */,$contents) ]; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
elsif ($arg =~ /:/) { |
|
108
|
0
|
|
|
|
|
|
$arg = [ split(/ *: */,$contents) ]; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif ($arg =~ /;/) { |
|
111
|
0
|
|
|
|
|
|
$arg = [ split(/ *; */,$contents) ]; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
else { |
|
114
|
0
|
|
|
|
|
|
$arg = [ split(/ *, */,$contents) ]; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
elsif ($arg =~ /^\{(.*)\}$/) { |
|
118
|
0
|
|
|
|
|
|
$contents = $1; |
|
119
|
0
|
0
|
|
|
|
|
if ($arg =~ /\|/) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$arg = { split(/ *[\|=>]+ */,$contents) }; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
elsif ($arg =~ /:/) { |
|
123
|
0
|
|
|
|
|
|
$arg = { split(/ *[:=>]+ */,$contents) }; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
elsif ($arg =~ /;/) { |
|
126
|
0
|
|
|
|
|
|
$arg = { split(/ *[;=>]+ */,$contents) }; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
else { |
|
129
|
0
|
|
|
|
|
|
$arg = { split(/ *[,=>]+ */,$contents) }; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
0
|
|
|
|
|
|
push(@$args, $arg); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
0
|
|
|
|
|
|
push(@$events, [ $service, $name, $method, $args ]); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _print_usage { |
|
139
|
0
|
|
|
0
|
|
|
print STDERR "--------------------------------------------------------------------\n"; |
|
140
|
0
|
|
|
|
|
|
print STDERR "Usage: $0 [options] [] [ []] [:returntype]\n"; |
|
141
|
0
|
|
|
|
|
|
print STDERR " --app= default basename of options file (when file not specified)\n"; |
|
142
|
0
|
|
|
|
|
|
print STDERR " --prefix= base directory of installed software (i.e. /usr/local)\n"; |
|
143
|
0
|
|
|
|
|
|
print STDERR " --debug_options debug the option parsing process\n"; |
|
144
|
0
|
|
|
|
|
|
print STDERR " --perlinc= directories to add to \@INC to find perl modules\n"; |
|
145
|
0
|
|
|
|
|
|
print STDERR " --import= additional config files to read\n"; |
|
146
|
0
|
|
|
|
|
|
print STDERR " --context_class= class, default=App::Context::Cmd\n"; |
|
147
|
0
|
|
|
|
|
|
print STDERR " --debug= set debug level and scope, default=0\n"; |
|
148
|
0
|
|
|
|
|
|
print STDERR " --help or -? print this message\n"; |
|
149
|
0
|
|
|
|
|
|
print STDERR "--App::Context::Cmd-------------------------------------------------\n"; |
|
150
|
0
|
|
|
|
|
|
print STDERR " --service= default curr service (default=SessionObject)\n"; |
|
151
|
0
|
|
|
|
|
|
print STDERR " --name= default curr name (default=default)\n"; |
|
152
|
0
|
|
|
|
|
|
print STDERR " --method= default curr method (default=content)\n"; |
|
153
|
0
|
|
|
|
|
|
print STDERR " --args= default curr args (default=)\n"; |
|
154
|
0
|
|
|
|
|
|
print STDERR " --returntype= default curr return type (default=default)\n"; |
|
155
|
0
|
|
|
|
|
|
print STDERR " --session_class= default=App::Session\n"; |
|
156
|
0
|
|
|
|
|
|
print STDERR " --conf_class= default=App::Conf::File\n"; |
|
157
|
0
|
|
|
|
|
|
print STDERR " --so_= set SessionObject default value\n"; |
|
158
|
0
|
|
|
|
|
|
print STDERR "--App::Conf::File---------------------------------------------------\n"; |
|
159
|
0
|
|
|
|
|
|
print STDERR " --debug_conf debug the configuration process\n"; |
|
160
|
0
|
|
|
|
|
|
print STDERR " --conf_type= type of data (name of Serializer) in conf_file\n"; |
|
161
|
0
|
|
|
|
|
|
print STDERR " --conf_file= file name for full config file\n"; |
|
162
|
0
|
|
|
|
|
|
print STDERR " --conf_serializer_class= class, default=App::Serializer\n"; |
|
163
|
0
|
|
|
|
|
|
print STDERR "--Examples----------------------------------------------------------\n"; |
|
164
|
0
|
|
|
|
|
|
print STDERR " --debug=1 (global debug)\n"; |
|
165
|
0
|
|
|
|
|
|
print STDERR " --debug=1,App::Context (debug class only)\n"; |
|
166
|
0
|
|
|
|
|
|
print STDERR " --debug=3,App::Context,App::Session (multiple classes)\n"; |
|
167
|
0
|
|
|
|
|
|
print STDERR " --debug=6,App::Repository::DBI.get_rows (indiv. methods)\n"; |
|
168
|
0
|
|
|
|
|
|
print STDERR "--------------------------------------------------------------------\n"; |
|
169
|
0
|
|
|
|
|
|
exit(1); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
############################################################################# |
|
173
|
|
|
|
|
|
|
# user() |
|
174
|
|
|
|
|
|
|
############################################################################# |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 user() |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The user() method returns the username of the authenticated user. |
|
179
|
|
|
|
|
|
|
The special name, "guest", refers to the unauthenticated (anonymous) user. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
* Signature: $username = $context->user(); |
|
182
|
|
|
|
|
|
|
* Param: void |
|
183
|
|
|
|
|
|
|
* Return: string |
|
184
|
|
|
|
|
|
|
* Throws: |
|
185
|
|
|
|
|
|
|
* Since: 0.01 |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Sample Usage: |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$username = $context->user(); |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub user { |
|
194
|
0
|
0
|
|
0
|
1
|
|
&App::sub_entry if ($App::trace); |
|
195
|
0
|
|
|
|
|
|
my $self = shift; |
|
196
|
0
|
|
0
|
|
|
|
my $user = $self->{user} || getlogin || (getpwuid($<))[0] || "guest"; |
|
197
|
0
|
0
|
|
|
|
|
&App::sub_exit($user) if ($App::trace); |
|
198
|
0
|
|
|
|
|
|
$user; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |
|
202
|
|
|
|
|
|
|
|