Changeset 214
- Timestamp:
- 09/24/06 00:09:55 (2 years ago)
- Files:
-
- trunk/MANIFEST (modified) (1 diff)
- trunk/lib/AxKit2/Config.pm (modified) (1 diff)
- trunk/lib/AxKit2/HTTPHeaders.pm (modified) (2 diffs)
- trunk/lib/AxKit2/Plugin.pm (modified) (1 diff)
- trunk/plugins/authenticate (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MANIFEST
r206 r214 118 118 plugins/aio/serve_file 119 119 plugins/aio/uri_to_file 120 plugins/authenticate 120 121 plugins/cachecache 121 122 plugins/demo/doc_viewer trunk/lib/AxKit2/Config.pm
r210 r214 797 797 my ($config, $param) = (shift, shift); 798 798 799 # the known subsections get a copy as well 799 # Don't overwrite values in subsections that are already set. 800 return if $config ne $self->config && !$param->{push} && exists $config->{$param->{key}}; 801 802 # Known subsections get a copy as well. 800 803 if (!exists $config->_subsections->{$param->{key}}) { 801 804 foreach my $objs (values %{$config->_subsections}) { trunk/lib/AxKit2/HTTPHeaders.pm
r162 r214 58 58 'requestLine', # first line of HTTP request (if request) 59 59 'parsed_cookies', # parsed cookie data 60 'lame' # HTTP/0.9 60 'lame', # HTTP/0.9 61 'user', # authenticated username 61 62 ); 62 63 … … 363 364 364 365 366 =head2 C<< $obj->user >> 367 368 Gets/sets the authenticated request username, if any. 369 370 =cut 371 372 sub user { 373 my AxKit2::HTTPHeaders $self = shift; 374 @_ and $self->{user} = shift; 375 return $self->{user}; 376 } 377 365 378 =head2 C<< $obj->request_uri >> 366 379 trunk/lib/AxKit2/Plugin.pm
r205 r214 275 275 This declaration: 276 276 277 sub conf_ foo_bar;277 sub conf_FooBar; 278 278 279 279 will create this entry: 280 280 281 $self->config('foo_bar');282 283 and can be used in a variety of ways in the config file:284 285 FooBar demo286 foobar demo287 fOObAR demo288 foo-bar demo289 foo_bar demo290 FOo_bAr demo291 292 which are all equivalent.293 294 This CamelCase declaration:295 296 sub conf_FooBar;297 298 will create this entry:299 300 281 $self->config('FooBar'); 301 282 302 and will have I<exactly> the same config file syntax as the previous example. 303 304 By default, multiple values are accepted and stored, while quoting is supported: 305 306 FooBar demo1 demo2 "demo 3" 307 308 For different ways of parsing/validating configuration directives, you can add 283 There are actually may possible variation on directive names that are all equivalent. Anywhere 284 a directive name is used, you can use any variation like this: 285 286 FooBar 287 foo_bar 288 foo-bar 289 FOO_BAR 290 foobar 291 292 and some more. This includes C<sub conf_FOO_BAR> or C<< $self->config("foo-bar") >>. 293 294 By default, a single values are accepted and stored, while quoting is supported: 295 296 FooBar "demo 3" 297 298 For different ways of validating configuration directives, you can add 309 299 a custom validation routine: 310 300 311 # use predefined " only one argument allowed" validator312 sub FooBar : Validate( TAKE1);313 314 # this directive takes a comma separated list ofvalues315 sub FooBar : Validate(sub { split(/,/,shift); });301 # use predefined "multiple strings" validator 302 sub FooBar : Validate(STRINGLIST); 303 304 # this directive takes one of two values 305 sub FooBar : Validate(sub { die "invalid value" if $_[1] !~ m/^(red|green)$/i; lc($_[1]); }); 316 306 317 307 If you want to have custom actions when the directive is parsed, supply a function body: 318 308 319 309 # store a database connection instead 320 sub FooBar { my ($ self, $value) = @_; return DBI->connect($value); }310 sub FooBar { my ($parser, $value) = @_; return DBI->connect($value); } 321 311 322 312 # preprocess parameters 323 sub FooBar { my ($self, @values) = @_; return join(",",@values); } 324 325 # return empty list means: don't store anything 326 sub FooBar { my ($self, @values) = @_; return (); } 313 sub FooBar { my ($parser, @values) = @_; return join(",",@values); } 327 314 328 315 Of course, all this can be combined: 329 316 330 317 # this is a rather nonsensical example, do you spot why? 331 sub FooBar : Validate(sub { split(/,/, shift); }) {332 my ($ self, @values) = @_;318 sub FooBar : Validate(sub { split(/,/,$_[1]); }) { 319 my ($parser, @values) = @_; 333 320 return join(",",@values); 334 321 } 335 322 323 For full details and more ways of designing configuration directives, see L<AxKit2::Config>. 336 324 337 325 =head1 AVAILABLE HOOKS
