| 1 | package Apache2::Controller::Directives; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Apache2::Controller::Directives - server config directives for A2C | ||
| 6 | |||
| 7 | =head1 VERSION | ||
| 8 | |||
| 9 | Version 1.001.001 | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | use version; | ||
| 14 | our $VERSION = version->new('1.001.001'); | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | # apache2 config file | ||
| 19 | PerlLoadModule Apache2::Controller::Directives | ||
| 20 | |||
| 21 | # for Apache2::Controller::Render::Template settings: | ||
| 22 | A2C_Render_Template_Path /var/myapp/templates | ||
| 23 | |||
| 24 | # etc. | ||
| 25 | |||
| 26 | All values are detainted using C<< m{ \A (.*) \z }mxs >>, | ||
| 27 | since they are assumed to be trusted because they come | ||
| 28 | from the server config file. As long as you don't give | ||
| 29 | your users the ability to set directives, it should be okay. | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings FATAL => 'all'; | ||
| 35 | use English '-no_match_vars'; | ||
| 36 | |||
| 37 | use Carp qw( croak ); | ||
| 38 | use Log::Log4perl qw(:easy); | ||
| 39 | use YAML::Syck; | ||
| 40 | use Readonly; | ||
| 41 | |||
| 42 | use Apache2::Module (); | ||
| 43 | use Apache2::Const -compile => qw( OR_ALL NO_ARGS TAKE1 ITERATE ITERATE2 RAW_ARGS ); | ||
| 44 | use Apache2::Controller::X; | ||
| 45 | |||
| 46 | use Apache2::Controller::Const qw( @RANDCHARS ); | ||
| 47 | |||
| 48 | my @directives = ( | ||
| 49 | |||
| 50 | # dispatch | ||
| 51 | { | ||
| 52 | name => 'A2C_Dispatch_Map', | ||
| 53 | func => __PACKAGE__.'::A2C_Dispatch_Map', | ||
| 54 | req_override => Apache2::Const::OR_ALL, | ||
| 55 | args_how => Apache2::Const::ITERATE, | ||
| 56 | errmsg => 'A2C_Dispatch_Map /path/to/yaml/syck/dispatch/map/file', | ||
| 57 | }, | ||
| 58 | |||
| 59 | # template rendering | ||
| 60 | { | ||
| 61 | name => 'A2C_Render_Template_Path', | ||
| 62 | func => __PACKAGE__.'::A2C_Render_Template_Path', | ||
| 63 | req_override => Apache2::Const::OR_ALL, | ||
| 64 | args_how => Apache2::Const::ITERATE, | ||
| 65 | errmsg => 'A2C_Render_Template_Path /primary/path [/second ... [/n]]', | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | name => 'A2C_Render_Template_Opts', | ||
| 69 | func => __PACKAGE__.'::A2C_Render_Template_Opts', | ||
| 70 | req_override => Apache2::Const::OR_ALL, | ||
| 71 | args_how => Apache2::Const::ITERATE2, | ||
| 72 | errmsg => q{ | ||
| 73 | # specify Template Toolkit options: | ||
| 74 | A2C_Render_Template_Opts INTERPOLATE 1 | ||
| 75 | A2C_Render_Template_Opts PRE_PROCESS header scripts style | ||
| 76 | A2C_Render_Template_Opts POST_CHOMP 1 | ||
| 77 | }, | ||
| 78 | }, | ||
| 79 | |||
| 80 | # session stuff | ||
| 81 | { | ||
| 82 | name => 'A2C_Session_Class', | ||
| 83 | func => __PACKAGE__.'::A2C_Session_Class', | ||
| 84 | req_override => Apache2::Const::OR_ALL, | ||
| 85 | args_how => Apache2::Const::TAKE1, | ||
| 86 | errmsg => 'example: A2C_Session_Class Apache::Session::File' | ||
| 87 | }, | ||
| 88 | { | ||
| 89 | name => 'A2C_Session_Opts', | ||
| 90 | func => __PACKAGE__.'::A2C_Session_Opts', | ||
| 91 | req_override => Apache2::Const::OR_ALL, | ||
| 92 | args_how => Apache2::Const::ITERATE2, | ||
| 93 | errmsg => q{ | ||
| 94 | # specify options for chosen Apache::Session subclass. | ||
| 95 | # example: | ||
| 96 | A2C_Session_Opts Directory /tmp/sessions | ||
| 97 | A2C_Session_Opts LockDirectory /var/lock/sessions | ||
| 98 | }, | ||
| 99 | }, | ||
| 100 | { | ||
| 101 | name => 'A2C_Session_Secret', | ||
| 102 | req_override => Apache2::Const::OR_ALL, | ||
| 103 | args_how => Apache2::Const::RAW_ARGS, | ||
| 104 | errmsg => q{ | ||
| 105 | # specify a constant secret for continuity across server restarts | ||
| 106 | A2C_Session_Secret foobar | ||
| 107 | |||
| 108 | # if no parameters, server startup will generate a secret, | ||
| 109 | # but this won't work for cluster farms etc. | ||
| 110 | A2C_Session_Secret | ||
| 111 | }, | ||
| 112 | }, | ||
| 113 | { | ||
| 114 | name => 'A2C_Session_Always_Save', | ||
| 115 | req_override => Apache2::Const::OR_ALL, | ||
| 116 | args_how => Apache2::Const::NO_ARGS, | ||
| 117 | errmsg => 'example: A2C_Session_Always_Save', | ||
| 118 | }, | ||
| 119 | { | ||
| 120 | name => 'A2C_Session_Cookie_Opts', | ||
| 121 | func => __PACKAGE__.'::A2C_Session_Cookie_Opts', | ||
| 122 | req_override => Apache2::Const::OR_ALL, | ||
| 123 | args_how => Apache2::Const::ITERATE2, | ||
| 124 | errmsg => q{ | ||
| 125 | # specify Apache2::Cookie options for session cookie. | ||
| 126 | # example: | ||
| 127 | A2C_Session_Cookie_Opts name myapp_sessionid | ||
| 128 | A2C_Session_Cookie_Opts expires +3M | ||
| 129 | }, | ||
| 130 | }, | ||
| 131 | |||
| 132 | # A2C:Methods | ||
| 133 | { | ||
| 134 | name => 'A2C_Skip_Bogus_Cookies', | ||
| 135 | req_override => Apache2::Const::OR_ALL, | ||
| 136 | args_how => Apache2::Const::NO_ARGS, | ||
| 137 | errmsg => 'example: A2C_Skip_Bogus_Cookies', | ||
| 138 | }, | ||
| 139 | |||
| 140 | # A2C:DBI::Connector | ||
| 141 | { | ||
| 142 | name => 'A2C_DBI_DSN', | ||
| 143 | req_override => Apache2::Const::OR_ALL, | ||
| 144 | args_how => Apache2::Const::TAKE1, | ||
| 145 | errmsg => 'example: A2C_DBI_DSN DBI:mysql:database=foo', | ||
| 146 | }, | ||
| 147 | { | ||
| 148 | name => 'A2C_DBI_User', | ||
| 149 | req_override => Apache2::Const::OR_ALL, | ||
| 150 | args_how => Apache2::Const::TAKE1, | ||
| 151 | errmsg => 'example: A2C_DBI_User database_username', | ||
| 152 | }, | ||
| 153 | { | ||
| 154 | name => 'A2C_DBI_Password', | ||
| 155 | req_override => Apache2::Const::OR_ALL, | ||
| 156 | args_how => Apache2::Const::TAKE1, | ||
| 157 | errmsg => 'example: A2C_DBI_Password database_password', | ||
| 158 | }, | ||
| 159 | { | ||
| 160 | name => 'A2C_DBI_Options', | ||
| 161 | req_override => Apache2::Const::OR_ALL, | ||
| 162 | args_how => Apache2::Const::ITERATE2, | ||
| 163 | errmsg => q{ | ||
| 164 | # specify DBI connect() options: | ||
| 165 | A2C_DBI_Options RaiseError 1 | ||
| 166 | A2C_DBI_Options AutoCommit 0 | ||
| 167 | }, | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | name => 'A2C_DBI_Cleanup', | ||
| 171 | req_override => Apache2::Const::OR_ALL, | ||
| 172 | args_how => Apache2::Const::TAKE1, | ||
| 173 | errmsg => 'example: A2C_DBI_Cleanup 1', | ||
| 174 | }, | ||
| 175 | { | ||
| 176 | name => 'A2C_DBI_Class', | ||
| 177 | req_override => Apache2::Const::OR_ALL, | ||
| 178 | args_how => Apache2::Const::TAKE1, | ||
| 179 | errmsg => 'example: A2C_DBI_Class MyApp::DBI', | ||
| 180 | }, | ||
| 181 | { | ||
| 182 | name => 'A2C_DBI_Pnotes_Name', | ||
| 183 | req_override => Apache2::Const::OR_ALL, | ||
| 184 | args_how => Apache2::Const::TAKE1, | ||
| 185 | errmsg => 'example: A2C_DBI_Pnotes_Name reader', | ||
| 186 | }, | ||
| 187 | |||
| 188 | # A2C:Auth::OpenID | ||
| 189 | { | ||
| 190 | name => 'A2C_Auth_OpenID_Login', | ||
| 191 | req_override => Apache2::Const::OR_ALL, | ||
| 192 | args_how => Apache2::Const::TAKE1, | ||
| 193 | errmsg => 'example: A2C_Auth_OpenID_Login /myapp/login', | ||
| 194 | }, | ||
| 195 | { | ||
| 196 | name => 'A2C_Auth_OpenID_Logout', | ||
| 197 | req_override => Apache2::Const::OR_ALL, | ||
| 198 | args_how => Apache2::Const::TAKE1, | ||
| 199 | errmsg => 'example: A2C_Auth_OpenID_Logout /myapp/logout', | ||
| 200 | }, | ||
| 201 | { | ||
| 202 | name => 'A2C_Auth_OpenID_Register', | ||
| 203 | req_override => Apache2::Const::OR_ALL, | ||
| 204 | args_how => Apache2::Const::TAKE1, | ||
| 205 | errmsg => 'example: A2C_Auth_OpenID_Register /myapp/register', | ||
| 206 | }, | ||
| 207 | { | ||
| 208 | name => 'A2C_Auth_OpenID_Timeout', | ||
| 209 | req_override => Apache2::Const::OR_ALL, | ||
| 210 | args_how => Apache2::Const::TAKE1, | ||
| 211 | errmsg => 'example: A2C_Auth_OpenID_Timeout +1h', | ||
| 212 | }, | ||
| 213 | { | ||
| 214 | name => 'A2C_Auth_OpenID_Table', | ||
| 215 | req_override => Apache2::Const::OR_ALL, | ||
| 216 | args_how => Apache2::Const::TAKE1, | ||
| 217 | errmsg => 'example: A2C_Auth_OpenID_Table openid', | ||
| 218 | }, | ||
| 219 | { | ||
| 220 | name => 'A2C_Auth_OpenID_User_Field', | ||
| 221 | req_override => Apache2::Const::OR_ALL, | ||
| 222 | args_how => Apache2::Const::TAKE1, | ||
| 223 | errmsg => 'example: A2C_Auth_OpenID_User_Field uname', | ||
| 224 | }, | ||
| 225 | { | ||
| 226 | name => 'A2C_Auth_OpenID_URL_Field', | ||
| 227 | req_override => Apache2::Const::OR_ALL, | ||
| 228 | args_how => Apache2::Const::TAKE1, | ||
| 229 | errmsg => 'example: A2C_Auth_OpenID_URL_Field openid_url', | ||
| 230 | }, | ||
| 231 | { | ||
| 232 | name => 'A2C_Auth_OpenID_DBI_Name', | ||
| 233 | req_override => Apache2::Const::OR_ALL, | ||
| 234 | args_how => Apache2::Const::TAKE1, | ||
| 235 | errmsg => 'example: A2C_Auth_OpenID_DBI_Name dbh', | ||
| 236 | }, | ||
| 237 | { | ||
| 238 | name => 'A2C_Auth_OpenID_Trust_Root', | ||
| 239 | req_override => Apache2::Const::OR_ALL, | ||
| 240 | args_how => Apache2::Const::TAKE1, | ||
| 241 | errmsg => 'example: A2C_Auth_OpenID_Trust_Root http://blah.tld/blah', | ||
| 242 | }, | ||
| 243 | { | ||
| 244 | name => 'A2C_Auth_OpenID_LWP_Class', | ||
| 245 | req_override => Apache2::Const::OR_ALL, | ||
| 246 | args_how => Apache2::Const::TAKE1, | ||
| 247 | errmsg => 'example: A2C_Auth_OpenID_LWP_Class LWPx::ParanoidAgent', | ||
| 248 | }, | ||
| 249 | { | ||
| 250 | name => 'A2C_Auth_OpenID_LWP_Opts', | ||
| 251 | req_override => Apache2::Const::OR_ALL, | ||
| 252 | args_how => Apache2::Const::ITERATE2, | ||
| 253 | errmsg => q{ | ||
| 254 | # specify options to the LWP class. example: | ||
| 255 | A2C_Auth_OpenID_LWP_Opts timeout 10 | ||
| 256 | A2C_Auth_OpenID_LWP_Opts agent A2C-openid | ||
| 257 | A2C_Auth_OpenID_LWP_Opts whitelisted_hosts 127.0.0.1 foo.bar.tld | ||
| 258 | # (don't whitelist stuff for ParanoidAgent unless you know | ||
| 259 | # what you're doing... we do this for the test suite) | ||
| 260 | }, | ||
| 261 | }, | ||
| 262 | { | ||
| 263 | name => 'A2C_Auth_OpenID_Allow_Login', | ||
| 264 | req_override => Apache2::Const::OR_ALL, | ||
| 265 | args_how => Apache2::Const::NO_ARGS, | ||
| 266 | errmsg => 'example: A2C_Auth_OpenID_Allow_Login', | ||
| 267 | }, | ||
| 268 | { | ||
| 269 | name => 'A2C_Auth_OpenID_Consumer_Secret', | ||
| 270 | req_override => Apache2::Const::OR_ALL, | ||
| 271 | args_how => Apache2::Const::RAW_ARGS, | ||
| 272 | errmsg => q{ | ||
| 273 | # specify a constant secret for continuity across server restarts | ||
| 274 | A2C_Auth_OpenID_Consumer_Secret foobar | ||
| 275 | |||
| 276 | # if no parameters, server startup will generate a secret, | ||
| 277 | # but this won't work for cluster farms etc. | ||
| 278 | A2C_Auth_OpenID_Consumer_Secret | ||
| 279 | }, | ||
| 280 | }, | ||
| 281 | { | ||
| 282 | name => 'A2C_Auth_OpenID_NoPreserveParams', | ||
| 283 | req_override => Apache2::Const::OR_ALL, | ||
| 284 | args_how => Apache2::Const::NO_ARGS, | ||
| 285 | errmsg => 'example: A2C_Auth_OpenID_NoPreserveParams', | ||
| 286 | }, | ||
| 287 | ); | ||
| 288 | |||
| 289 | Apache2::Module::add(__PACKAGE__, \@directives); | ||
| 290 | |||
| 291 | =head1 Apache2::Controller::Dispatch | ||
| 292 | |||
| 293 | See L<Apache2::Controller::Dispatch> | ||
| 294 | |||
| 295 | =head2 A2C_Dispatch_Map | ||
| 296 | |||
| 297 | This is the path to a file compatible with L<YAML::Syck>. | ||
| 298 | If you do not provide a C<< dispatch_map() >> subroutine, | ||
| 299 | the hash will be loaded with this file. | ||
| 300 | |||
| 301 | Different subclasses of L<Apache2::Controller::Dispatch> | ||
| 302 | have different data structures. YMMV. | ||
| 303 | |||
| 304 | Or, if you just specify a package name, it will generate | ||
| 305 | a dispatch map with one 'default' entry with that package. | ||
| 306 | |||
| 307 | =cut | ||
| 308 | |||
| 309 | sub A2C_Dispatch_Map { | ||
| 310 | my ($self, $parms, $value) = @_; | ||
| 311 | |||
| 312 | ($value) = $value =~ m{ \A (.*) \z }mxs; | ||
| 313 | |||
| 314 | if ($value =~ m{ :: }mxs) { | ||
| 315 | $self->{A2C_Dispatch_Map} = { default => $value }; | ||
| 316 | return; | ||
| 317 | } | ||
| 318 | |||
| 319 | my $file = $value; | ||
| 320 | # DEBUG("using file '$file' as A2C_Dispatch_Map"); | ||
| 321 | croak "A2C_Dispatch_Map $file does not exist or is not readable." | ||
| 322 | if !(-e $file && -f _ && -r _); | ||
| 323 | |||
| 324 | # why not go ahead and load the file! | ||
| 325 | |||
| 326 | # slurp it in so it can be detainted. | ||
| 327 | |||
| 328 | my $file_contents; | ||
| 329 | { local $/; | ||
| 330 | open my $loadfile_fh, '<', $file | ||
| 331 | || croak "Cannot read A2C_Dispatch_Map $file: $OS_ERROR"; | ||
| 332 | $file_contents = <$loadfile_fh>; | ||
| 333 | close $loadfile_fh; | ||
| 334 | } | ||
| 335 | |||
| 336 | eval { $self->{A2C_Dispatch_Map} = Load($file_contents) }; | ||
| 337 | croak "Could not load A2C_Dispatch_Map $file: $EVAL_ERROR" if $EVAL_ERROR; | ||
| 338 | |||
| 339 | # DEBUG("success!"); | ||
| 340 | return; | ||
| 341 | } | ||
| 342 | |||
| 343 | =head1 Apache2::Controller::Render::Template | ||
| 344 | |||
| 345 | See L<Apache2::Controller::Render::Template>. | ||
| 346 | |||
| 347 | =head2 A2C_Render_Template_Path | ||
| 348 | |||
| 349 | This is the base path for templates used by | ||
| 350 | Apache2::Controller::Render::Template. The directive takes only | ||
| 351 | one parameter and verifies that the directory exists and is readable. | ||
| 352 | |||
| 353 | (At startup time Apache2 is root... this should verify readability by | ||
| 354 | www user? Hrmm how is it going to figure out what user that is? | ||
| 355 | It will have to access the server config via $parms. Except that | ||
| 356 | this does not appear to work? It returns an empty hash.) | ||
| 357 | |||
| 358 | =cut | ||
| 359 | |||
| 360 | sub A2C_Render_Template_Path { | ||
| 361 | my ($self, $parms, @directories_untainted) = @_; | ||
| 362 | |||
| 363 | my @directories = map { | ||
| 364 | my ($val) = $_ =~ m{ \A (.*) \z }mxs; | ||
| 365 | $val; | ||
| 366 | } @directories_untainted; | ||
| 367 | |||
| 368 | # uhh... this doesn't work? | ||
| 369 | # my $srv_cfg = Apache2::Module::get_config($self, $parms->server); | ||
| 370 | # DEBUG(sub{"SERVER CONFIG:\n".Dump({ | ||
| 371 | # map {("$_" => $srv_cfg->{$_})} keys %{$srv_cfg} | ||
| 372 | # }) }); | ||
| 373 | # DEBUG("server is ".$parms->server); | ||
| 374 | |||
| 375 | # I need to figure out how to merge these or something | ||
| 376 | |||
| 377 | croak("A2C_Render_Template_Path '$_' does not exist or is not readable.") | ||
| 378 | for grep !( -d $_ && -r _ ), @directories; | ||
| 379 | |||
| 380 | my $current = $self->{A2C_Render_Template_Path} ||= [ ]; | ||
| 381 | DEBUG sub { "pushing (@directories) to (@{$current})" }; | ||
| 382 | |||
| 383 | push @{ $self->{A2C_Render_Template_Path} }, @directories; | ||
| 384 | } | ||
| 385 | |||
| 386 | =head2 A2C_Render_Template_Opts | ||
| 387 | |||
| 388 | <location "/where/template/is/used"> | ||
| 389 | A2C_Render_Template_Opts INTERPOLATE 1 | ||
| 390 | A2C_Render_Template_Opts PRE_PROCESS header meta style scripts | ||
| 391 | A2C_Render_Template_Opts POST_CHOMP 1 | ||
| 392 | </location> | ||
| 393 | |||
| 394 | Options for Template Toolkit. See L<Template>. | ||
| 395 | |||
| 396 | You can also implement C<<get_template_opts>> in your controller subclass, | ||
| 397 | which simply returns the hash reference of template options. | ||
| 398 | See L<Apache2::Controller::Render::Template>. | ||
| 399 | |||
| 400 | Note the behavior is to merge values specified at multiple levels | ||
| 401 | into array references. i.e. a subdirectory could specify an | ||
| 402 | additional C<<PRE_PROCESS>> template or whatever. YMMV. | ||
| 403 | It should be this way, at any rate! | ||
| 404 | |||
| 405 | =cut | ||
| 406 | |||
| 407 | sub A2C_Render_Template_Opts { | ||
| 408 | my ($self, $parms, $key, $val) = @_; | ||
| 409 | $self->hash_assign('A2C_Render_Template_Opts', $key, $val); | ||
| 410 | return; | ||
| 411 | } | ||
| 412 | |||
| 413 | =head1 Apache2::Controller::Session | ||
| 414 | |||
| 415 | See L<Apache2::Controller::Session>. | ||
| 416 | |||
| 417 | =head2 A2C_Session_Class | ||
| 418 | |||
| 419 | A2C_Session_Class Apache::Session::File | ||
| 420 | |||
| 421 | Single argument, the class for the tied session hash. L<Apache::Session>. | ||
| 422 | |||
| 423 | =cut | ||
| 424 | |||
| 425 | sub A2C_Session_Class { | ||
| 426 | my ($self, $parms, $class) = @_; | ||
| 427 | ($class) = $class =~ m{ \A (.*) \z }mxs; | ||
| 428 | $self->{A2C_Session_Class} = $class; | ||
| 429 | } | ||
| 430 | |||
| 431 | =head2 A2C_Session_Opts | ||
| 432 | |||
| 433 | Multiple arguments | ||
| 434 | |||
| 435 | A2C_Session_Opts Directory /tmp/sessions | ||
| 436 | A2C_Session_Opts LockDirectory /var/lock/sessions | ||
| 437 | |||
| 438 | =cut | ||
| 439 | |||
| 440 | sub A2C_Session_Opts { | ||
| 441 | my ($self, $parms, $key, $val) = @_; | ||
| 442 | $self->hash_assign('A2C_Session_Opts', $key, $val); | ||
| 443 | return; | ||
| 444 | } | ||
| 445 | |||
| 446 | =head2 A2C_Session_Secret | ||
| 447 | |||
| 448 | # generate a random 30-character string: | ||
| 449 | A2C_Session_Secret | ||
| 450 | |||
| 451 | # specify your own string: | ||
| 452 | A2C_Session_Secret jsd9e9j#*@JMf39kc3 | ||
| 453 | |||
| 454 | This server-wide constant string will used to verify the session id. | ||
| 455 | See L<Apache2::Controller::Session>. | ||
| 456 | |||
| 457 | If you don't specify the value, it will generate a default 30-character | ||
| 458 | random string, but this will regenerate on server restarts, and would not | ||
| 459 | work for a cluster of servers serving the same application. | ||
| 460 | |||
| 461 | =cut | ||
| 462 | |||
| 463 | sub A2C_Session_Secret { | ||
| 464 | my ($self, $parms, $val) = @_; | ||
| 465 | if (!defined $val || $val =~ m{ \A \s* \z }mxs) { | ||
| 466 | srand; | ||
| 467 | $val = join('', map $RANDCHARS[int(rand(@RANDCHARS))], 1..30); | ||
| 468 | } | ||
| 469 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 470 | $self->{A2C_Session_Secret} = $val; | ||
| 471 | } | ||
| 472 | |||
| 473 | =head2 A2C_Session_Always_Save | ||
| 474 | |||
| 475 | A2C_Session_Always_Save | ||
| 476 | |||
| 477 | Takes no arguments. If directed, L<Apache2::Controller::Session> | ||
| 478 | will update a top-level timestamp in | ||
| 479 | C<< $r->pnotes->{a2c}{session}{a2c_timestamp} >> so that | ||
| 480 | L<Apache::Session> will always save. | ||
| 481 | |||
| 482 | =cut | ||
| 483 | |||
| 484 | sub A2C_Session_Always_Save { | ||
| 485 | my ($self, $parms) = @_; | ||
| 486 | $self->{A2C_Session_Always_Save} = 1; | ||
| 487 | } | ||
| 488 | |||
| 489 | =head2 A2C_Session_Cookie_Opts | ||
| 490 | |||
| 491 | A2C_Session_Cookie_Opts name myapp_sessionid | ||
| 492 | A2C_Session_Cookie_Opts expires +3M | ||
| 493 | |||
| 494 | Multiple arguments. | ||
| 495 | L<Apache2::Controller::Session::Cookie>, | ||
| 496 | L<Apache2::Cookie> | ||
| 497 | |||
| 498 | =cut | ||
| 499 | |||
| 500 | sub A2C_Session_Cookie_Opts { | ||
| 501 | my ($self, $parms, $key, $val) = @_; | ||
| 502 | $self->hash_assign('A2C_Session_Cookie_Opts', $key, $val); | ||
| 503 | return; | ||
| 504 | } | ||
| 505 | |||
| 506 | =head1 Apache2::Controller::Methods | ||
| 507 | |||
| 508 | Misc. directives that apply to most A2C objects that inherit | ||
| 509 | L<Apache2::Controller::Methods>. | ||
| 510 | |||
| 511 | =head2 A2C_Skip_Bogus_Cookies | ||
| 512 | |||
| 513 | A2C_Skip_Bogus_Cookies | ||
| 514 | |||
| 515 | Takes no arguments. If present, cookie jar will be constructed | ||
| 516 | using C<< eval { } >> that skips NOTOKEN errors. | ||
| 517 | See L<Apache2::Controller::Methods/get_cookie_jar>. | ||
| 518 | |||
| 519 | =cut | ||
| 520 | |||
| 521 | sub A2C_Skip_Bogus_Cookies { | ||
| 522 | my ($self, $parms) = @_; | ||
| 523 | $self->{A2C_Skip_Bogus_Cookies} = 1; | ||
| 524 | } | ||
| 525 | |||
| 526 | =head1 Apache2::Controller::DBI::Connector | ||
| 527 | |||
| 528 | See L<Apache2::Controller::DBI::Connector>. | ||
| 529 | |||
| 530 | =head2 A2C_DBI_DSN | ||
| 531 | |||
| 532 | A2C_DBI_DSN DBI:mysql:database=foobar;host=localhost | ||
| 533 | |||
| 534 | Single argument, the DSN string. L<DBI> | ||
| 535 | |||
| 536 | =cut | ||
| 537 | |||
| 538 | sub A2C_DBI_DSN { | ||
| 539 | my ($self, $parms, $dsn) = @_; | ||
| 540 | ($dsn) = $dsn =~ m{ \A (.*) \z }mxs; | ||
| 541 | $self->{A2C_DBI_DSN} = $dsn; | ||
| 542 | } | ||
| 543 | |||
| 544 | =head2 A2C_DBI_User | ||
| 545 | |||
| 546 | A2C_DBI_User heebee | ||
| 547 | |||
| 548 | Single argument, the DBI username. | ||
| 549 | |||
| 550 | =cut | ||
| 551 | |||
| 552 | sub A2C_DBI_User { | ||
| 553 | my ($self, $parms, $user) = @_; | ||
| 554 | ($user) = $user =~ m{ \A (.*) \z }mxs; | ||
| 555 | $self->{A2C_DBI_User} = $user; | ||
| 556 | } | ||
| 557 | |||
| 558 | =head2 A2C_DBI_Password | ||
| 559 | |||
| 560 | A2C_DBI_Password jeebee | ||
| 561 | |||
| 562 | Single argument, the DBI password. | ||
| 563 | |||
| 564 | =cut | ||
| 565 | |||
| 566 | sub A2C_DBI_Password { | ||
| 567 | my ($self, $parms, $password) = @_; | ||
| 568 | ($password) = $password =~ m{ \A (.*) \z }mxs; | ||
| 569 | $self->{A2C_DBI_Password} = $password; | ||
| 570 | } | ||
| 571 | |||
| 572 | =head2 A2C_DBI_Options | ||
| 573 | |||
| 574 | Multiple arguments. | ||
| 575 | |||
| 576 | A2C_DBI_Options RaiseError 1 | ||
| 577 | A2C_DBI_Options AutoCommit 0 | ||
| 578 | |||
| 579 | =cut | ||
| 580 | |||
| 581 | sub A2C_DBI_Options { | ||
| 582 | my ($self, $parms, $key, $val) = @_; | ||
| 583 | $self->hash_assign('A2C_DBI_Options', $key, $val); | ||
| 584 | return; | ||
| 585 | } | ||
| 586 | |||
| 587 | =head2 A2C_DBI_Cleanup | ||
| 588 | |||
| 589 | Boolean. | ||
| 590 | |||
| 591 | A2C_DBI_Cleanup 1 | ||
| 592 | |||
| 593 | =cut | ||
| 594 | |||
| 595 | sub A2C_DBI_Cleanup { | ||
| 596 | my ($self, $parms, $val) = @_; | ||
| 597 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 598 | $self->{A2C_DBI_Cleanup} = $val; | ||
| 599 | return; | ||
| 600 | } | ||
| 601 | |||
| 602 | =head2 A2C_DBI_Pnotes_Name | ||
| 603 | |||
| 604 | String value. | ||
| 605 | |||
| 606 | A2C_DBI_Pnotes_Name reader | ||
| 607 | |||
| 608 | =cut | ||
| 609 | |||
| 610 | sub A2C_DBI_Pnotes_Name { | ||
| 611 | my ($self, $parms, $val) = @_; | ||
| 612 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 613 | $self->{A2C_DBI_Pnotes_Name} = $val; | ||
| 614 | return; | ||
| 615 | } | ||
| 616 | |||
| 617 | =head2 A2C_DBI_Class | ||
| 618 | |||
| 619 | If you subclass DBI, specify the name of your DBI subclass here. | ||
| 620 | |||
| 621 | A2C_DBI_Class MyApp::DBI | ||
| 622 | |||
| 623 | Note that this is connected with a string eval which is slow. | ||
| 624 | If you don't use it, it uses a block eval to connect DBI. | ||
| 625 | |||
| 626 | =cut | ||
| 627 | |||
| 628 | sub A2C_DBI_Class { | ||
| 629 | my ($self, $parms, $val) = @_; | ||
| 630 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 631 | $self->{A2C_DBI_Class} = $val; | ||
| 632 | } | ||
| 633 | |||
| 634 | =head1 Apache2::Controller::Auth::OpenID | ||
| 635 | |||
| 636 | See L<Apache2::Controller::Auth::OpenID>. | ||
| 637 | |||
| 638 | =head2 A2C_Auth_OpenID_Login | ||
| 639 | |||
| 640 | A2C_Auth_OpenID_Login login | ||
| 641 | |||
| 642 | The URI path for your login controller page. | ||
| 643 | |||
| 644 | If you start the value with a '/', it thinks you mean | ||
| 645 | an absolute URI. | ||
| 646 | |||
| 647 | If you do not start the value with a '/', it thinks you | ||
| 648 | mean a uri relative to | ||
| 649 | the location path where the directive was declared. | ||
| 650 | |||
| 651 | Examples: | ||
| 652 | |||
| 653 | <Location '/foo/bar'> | ||
| 654 | A2C_Auth_OpenID_Login /login | ||
| 655 | </Location> | ||
| 656 | |||
| 657 | The user would be redirected to absolute uri '/login'. | ||
| 658 | |||
| 659 | <Location '/loungy/vegas/entertainment'> | ||
| 660 | A2C_Auth_OpenID_Login kenny_loggins | ||
| 661 | </Location> | ||
| 662 | |||
| 663 | The user would be redirected to | ||
| 664 | C<< /loungy/vegas/entertainment/kenny_loggins >> | ||
| 665 | if they are not logged in. | ||
| 666 | |||
| 667 | These conventions are the same for C<< A2C_Auth_OpenID_Logout >> | ||
| 668 | and C<< A2C_Auth_OpenID_Register >>. | ||
| 669 | |||
| 670 | Default is the path where the controller is declared, appended with '/login'. | ||
| 671 | Access will be allowed. | ||
| 672 | |||
| 673 | =cut | ||
| 674 | |||
| 675 | sub A2C_Auth_OpenID_Login { | ||
| 676 | my ($self, $parms, $val) = @_; | ||
| 677 | $val = 'login' if !defined $val; | ||
| 678 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 679 | $val = $parms->path.'/'.$val if $val !~ m{ \A / }mxs; | ||
| 680 | $self->{A2C_Auth_OpenID_Login} = $val; | ||
| 681 | } | ||
| 682 | |||
| 683 | =head2 A2C_Auth_OpenID_Logout | ||
| 684 | |||
| 685 | A2C_Auth_OpenID_Logout logout | ||
| 686 | |||
| 687 | The URI path for your logout controller page. | ||
| 688 | |||
| 689 | Logout is processed automatically, resetting the flag and | ||
| 690 | timestamp in the session hash. So you just need to present | ||
| 691 | a page that says "Good riddance" or something. | ||
| 692 | |||
| 693 | Same conventions apply as to C<< A2C_Auth_OpenID_Login >>. | ||
| 694 | Default is the path where the controller is declared, appended with '/logout'. | ||
| 695 | Access will be allowed. | ||
| 696 | |||
| 697 | =cut | ||
| 698 | |||
| 699 | sub A2C_Auth_OpenID_Logout { | ||
| 700 | my ($self, $parms, $val) = @_; | ||
| 701 | $val = 'logout' if !defined $val; | ||
| 702 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 703 | $val = $parms->path.'/'.$val if $val !~ m{ \A / }mxs; | ||
| 704 | $self->{A2C_Auth_OpenID_Logout} = $val; | ||
| 705 | } | ||
| 706 | |||
| 707 | =head2 A2C_Auth_OpenID_Register | ||
| 708 | |||
| 709 | A2C_Auth_OpenID_Register register | ||
| 710 | |||
| 711 | The path for your registration page, where you will ask the user | ||
| 712 | to sign up and associate a username with the openid url. | ||
| 713 | |||
| 714 | Same conventions apply as to C<< A2C_Auth_OpenID_Login >>. | ||
| 715 | Default is the path where the controller is declared, appended with '/register'. | ||
| 716 | Access will be allowed. | ||
| 717 | |||
| 718 | =cut | ||
| 719 | |||
| 720 | sub A2C_Auth_OpenID_Register { | ||
| 721 | my ($self, $parms, $val) = @_; | ||
| 722 | $val = 'register' if !defined $val; | ||
| 723 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 724 | $val = $parms->path.'/'.$val if $val !~ m{ \A / }mxs; | ||
| 725 | $self->{A2C_Auth_OpenID_Register} = $val; | ||
| 726 | } | ||
| 727 | |||
| 728 | =head2 A2C_Auth_OpenID_Timeout | ||
| 729 | |||
| 730 | A2C_Auth_OpenID_Timeout +1h | ||
| 731 | |||
| 732 | Idle timeout in seconds, +2m, +3h, +4D, +6M, +7Y, or 'no timeout'. | ||
| 733 | Default is 1 hour. A month is actually 30 days, a year 365. | ||
| 734 | |||
| 735 | If you use 'no timeout' then logins will never expire. | ||
| 736 | This probably is not a good idea because OpenID url's can | ||
| 737 | be revoked, and because the login process can be a transparent | ||
| 738 | series of redirects if the user has something like | ||
| 739 | Verisign's SeatBelt plugin. | ||
| 740 | |||
| 741 | If you're doing some sort of cluster application or load balancing | ||
| 742 | and sharing the session between servers, make sure all your servers | ||
| 743 | are synchronized with NTP. | ||
| 744 | |||
| 745 | =cut | ||
| 746 | |||
| 747 | my %time_multiplier = ( | ||
| 748 | s => 1, | ||
| 749 | m => 60, | ||
| 750 | h => 60 * 60, | ||
| 751 | D => 60 * 60 * 24, | ||
| 752 | M => 60 * 60 * 24 * 30, | ||
| 753 | Y => 60 * 60 * 24 * 365, | ||
| 754 | ); | ||
| 755 | |||
| 756 | sub A2C_Auth_OpenID_Timeout { | ||
| 757 | my ($self, $parms, $val) = @_; | ||
| 758 | $val ||= '+1h'; | ||
| 759 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 760 | if ($val ne 'no timeout') { | ||
| 761 | my ($num, $period) = $val =~ m{ \A \+? (\d+) ([YMDhms]?) \z }mxs; | ||
| 762 | $period ||= 's'; | ||
| 763 | croak("A2C_Auth_OpenID_Timeout invalid format") | ||
| 764 | if !$num || !exists $time_multiplier{$period}; | ||
| 765 | $val = $num * $time_multiplier{$period}; | ||
| 766 | } | ||
| 767 | |||
| 768 | $self->{A2C_Auth_OpenID_Timeout} = $val; | ||
| 769 | } | ||
| 770 | |||
| 771 | =head2 A2C_Auth_OpenID_Table | ||
| 772 | |||
| 773 | A2C_Auth_OpenID_Login openid | ||
| 774 | |||
| 775 | Name of the table in your connected database containing the | ||
| 776 | user name and OpenID url fields. Default == "openid". | ||
| 777 | |||
| 778 | =cut | ||
| 779 | |||
| 780 | sub A2C_Auth_OpenID_Table { | ||
| 781 | my ($self, $parms, $val) = @_; | ||
| 782 | $val ||= 'openid'; | ||
| 783 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 784 | $self->{A2C_Auth_OpenID_Table} = $val; | ||
| 785 | } | ||
| 786 | |||
| 787 | =head2 A2C_Auth_OpenID_User_Field | ||
| 788 | |||
| 789 | A2C_Auth_OpenID_User_Field uname | ||
| 790 | |||
| 791 | Name of username field in table. Default == "uname". | ||
| 792 | |||
| 793 | =cut | ||
| 794 | |||
| 795 | sub A2C_Auth_OpenID_User_Field { | ||
| 796 | my ($self, $parms, $val) = @_; | ||
| 797 | $val ||= 'uname'; | ||
| 798 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 799 | $self->{A2C_Auth_OpenID_User_Field} = $val; | ||
| 800 | } | ||
| 801 | |||
| 802 | =head2 A2C_Auth_OpenID_URL_Field | ||
| 803 | |||
| 804 | A2C_Auth_OpenID_URL_Field openid_url | ||
| 805 | |||
| 806 | Name of OpenID URL field in table. Default == "openid_url". | ||
| 807 | |||
| 808 | =cut | ||
| 809 | |||
| 810 | sub A2C_Auth_OpenID_URL_Field { | ||
| 811 | my ($self, $parms, $val) = @_; | ||
| 812 | $val ||= 'openid_url'; | ||
| 813 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 814 | $self->{A2C_Auth_OpenID_URL_Field} = $val; | ||
| 815 | } | ||
| 816 | |||
| 817 | =head2 A2C_Auth_OpenID_DBI_Name | ||
| 818 | |||
| 819 | A2C_Auth_OpenID_DBI_Name dbh | ||
| 820 | |||
| 821 | Name in C<< $r->pnotes->{a2c} >> of the connected L<DBI> handle. | ||
| 822 | Default == "dbh". | ||
| 823 | |||
| 824 | =cut | ||
| 825 | |||
| 826 | sub A2C_Auth_OpenID_DBI_Name { | ||
| 827 | my ($self, $parms, $val) = @_; | ||
| 828 | $val ||= 'dbh'; | ||
| 829 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 830 | $self->{A2C_Auth_OpenID_DBI_Name} = $val; | ||
| 831 | } | ||
| 832 | |||
| 833 | =head2 A2C_Auth_OpenID_Trust_Root | ||
| 834 | |||
| 835 | A2C_Auth_OpenID_Trust_Root http://blah.tld/blah | ||
| 836 | |||
| 837 | The trust_root param to pass to the user's OpenID server. | ||
| 838 | See L<Net::OpenID::Consumer>. Default is the top of | ||
| 839 | the web site with whatever scheme, host and port that | ||
| 840 | is currently being requested. | ||
| 841 | |||
| 842 | =cut | ||
| 843 | |||
| 844 | sub A2C_Auth_OpenID_Trust_Root { | ||
| 845 | my ($self, $parms, $val) = @_; | ||
| 846 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 847 | $self->{A2C_Auth_OpenID_Trust_Root} = $val; | ||
| 848 | } | ||
| 849 | |||
| 850 | =head2 A2C_Auth_OpenID_LWP_Class | ||
| 851 | |||
| 852 | A2C_Auth_OpenID_LWP_Class LWPx::ParanoidAgent | ||
| 853 | |||
| 854 | Name of the L<LWP> class to use. By default it uses | ||
| 855 | L<LWPx::ParanoidAgent> but not L<LWPx::ParanoidAgent::DashT>, | ||
| 856 | as that one is not available as a Debian package, I | ||
| 857 | was unsuccessful building it with dh-make-perl, and I | ||
| 858 | want to be able to distribute to Debian. | ||
| 859 | |||
| 860 | =cut | ||
| 861 | |||
| 862 | sub A2C_Auth_OpenID_LWP_Class { | ||
| 863 | my ($self, $parms, $val) = @_; | ||
| 864 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 865 | $self->{A2C_Auth_OpenID_LWP_Class} = $val || 'LWPx::ParanoidAgent'; | ||
| 866 | } | ||
| 867 | |||
| 868 | =head2 A2C_Auth_OpenID_LWP_Opts | ||
| 869 | |||
| 870 | Specify options to the LWP class. | ||
| 871 | |||
| 872 | A2C_Auth_OpenID_LWP_Opts timeout 10 | ||
| 873 | A2C_Auth_OpenID_LWP_Opts agent A2C-openid | ||
| 874 | A2C_Auth_OpenID_LWP_Opts whitelisted_hosts [ 127.0.0.1 foo.bar.com ] | ||
| 875 | |||
| 876 | Don't whitelist stuff for ParanoidAgent unless you know | ||
| 877 | what you're doing... I was going do this for the test suite to let | ||
| 878 | the module call the temporary OpenID server set up on localhost. | ||
| 879 | |||
| 880 | But that ends up not working in the test suite because of some other | ||
| 881 | problem trying to connect to a port which I don't know necessarily? | ||
| 882 | ("Error fetching URL: No sock from bgsend"). | ||
| 883 | So the test suite just uses plain old LWP::UserAgent. | ||
| 884 | |||
| 885 | This uses C<< hash_assign() >> to assign the options. | ||
| 886 | |||
| 887 | Use [ ] to force an array ref for a single option that has | ||
| 888 | to be an arrayref: | ||
| 889 | |||
| 890 | A2C_Auth_OpenID_LWP_Opts whitelisted_hosts [ 192.168.34.5 ] | ||
| 891 | |||
| 892 | but don't use commas, it's tricky. | ||
| 893 | |||
| 894 | =cut | ||
| 895 | |||
| 896 | sub A2C_Auth_OpenID_LWP_Opts { | ||
| 897 | my ($self, $parms, $key, $val) = @_; | ||
| 898 | $self->hash_assign('A2C_Auth_OpenID_LWP_Opts', $key, $val); | ||
| 899 | return; | ||
| 900 | } | ||
| 901 | |||
| 902 | =head2 A2C_Auth_OpenID_Allow_Login | ||
| 903 | |||
| 904 | A2C_Auth_OpenID_Allow_Login | ||
| 905 | |||
| 906 | Takes no arguments. If directed, L<Apache2::Controller::Auth::OpenID> | ||
| 907 | will allow all login attempts and will not attempt to authenticate | ||
| 908 | with OpenID. Useful for debugging your application on your laptop | ||
| 909 | when you are not connected to the Internet. | ||
| 910 | |||
| 911 | =cut | ||
| 912 | |||
| 913 | sub A2C_Auth_OpenID_Allow_Login { | ||
| 914 | my ($self, $parms) = @_; | ||
| 915 | $self->{A2C_Auth_OpenID_Allow_Login} = 1; | ||
| 916 | } | ||
| 917 | |||
| 918 | =head2 A2C_Auth_OpenID_Consumer_Secret | ||
| 919 | |||
| 920 | # generate a random 30-character string: | ||
| 921 | A2C_Auth_OpenID_Consumer_Secret | ||
| 922 | |||
| 923 | # specify your own string: | ||
| 924 | A2C_Auth_OpenID_Consumer_Secret jsd9e9j#*@JMf39kc3 | ||
| 925 | |||
| 926 | This server-wide constant string will be appended to the value of | ||
| 927 | time() for the sha224_base64 hash provided as the consumer_secret. | ||
| 928 | See L<Net::OpenID::Consumer/consumer_secret>. | ||
| 929 | |||
| 930 | If you don't specify the value, it will generate a default 30-character | ||
| 931 | random string, but this will regenerate on server restarts, and would not | ||
| 932 | work for a cluster of servers serving the same application. | ||
| 933 | |||
| 934 | |||
| 935 | =cut | ||
| 936 | |||
| 937 | sub A2C_Auth_OpenID_Consumer_Secret { | ||
| 938 | my ($self, $parms, $val) = @_; | ||
| 939 | if (!defined $val || $val =~ m{ \A \s* \z }mxs) { | ||
| 940 | srand; | ||
| 941 | $val = join('', map $RANDCHARS[int(rand(@RANDCHARS))], 1..30); | ||
| 942 | } | ||
| 943 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 944 | $self->{A2C_Auth_OpenID_Consumer_Secret} = $val; | ||
| 945 | } | ||
| 946 | |||
| 947 | =head2 A2C_Auth_OpenID_NoPreserveParams | ||
| 948 | |||
| 949 | A2C_Auth_OpenID_NoPreserveParams | ||
| 950 | |||
| 951 | Takes no arguments. If directed, L<Apache2::Controller::Auth::OpenID> | ||
| 952 | will not preserve GET/POST params. I know a double-negative is | ||
| 953 | frowned upon, but it makes the most sense here, because preserving | ||
| 954 | GET/POST params should be the default behavior, and this turns | ||
| 955 | off that behavior. | ||
| 956 | |||
| 957 | =cut | ||
| 958 | |||
| 959 | sub A2C_Auth_OpenID_NoPreserveParams { | ||
| 960 | my ($self, $parms) = @_; | ||
| 961 | $self->{A2C_Auth_OpenID_NoPreserveParams} = 1; | ||
| 962 | } | ||
| 963 | |||
| 964 | =head2 hash_assign | ||
| 965 | |||
| 966 | This is not a configuration option, but an internal routine | ||
| 967 | that we use to assign ITERATE2 options in a consistent way, | ||
| 968 | or so one might hope. I'm not sure I fully understand the | ||
| 969 | behavior and I haven't written tests for directives. | ||
| 970 | |||
| 971 | If a single value is specified, it is assigned as a scalar. | ||
| 972 | |||
| 973 | If multiple values are specified (on the same configuration | ||
| 974 | directive call or in multiple calls) they are successively | ||
| 975 | |||
| 976 | This is sort of similar the way that C<< $r->param >> will get | ||
| 977 | a string or an array ref depending if the var has been named | ||
| 978 | more than once. | ||
| 979 | |||
| 980 | Use [ ] to force an array ref for a single option that has | ||
| 981 | to be an arrayref: | ||
| 982 | |||
| 983 | A2C_Auth_OpenID_LWP_Opts whitelisted_hosts [ 127.0.0.1 ] | ||
| 984 | |||
| 985 | but don't use commas, it's tricky. The closing ] is actually | ||
| 986 | ignored, but you should use it to make it look sensible. | ||
| 987 | |||
| 988 | As a result, you can't use '[' or ']' for the values of | ||
| 989 | any of these options... but you "shouldn't need to do that." | ||
| 990 | |||
| 991 | See L<Apache2::Const/ITERATE2>. | ||
| 992 | |||
| 993 | =cut | ||
| 994 | |||
| 995 | sub hash_assign { | ||
| 996 | my ($self, $directive, $key, $val) = @_; | ||
| 997 | |||
| 998 | croak "No value for $directive {$key}." if !$val; | ||
| 999 | |||
| 1000 | ($key) = $key =~ m{ \A (.*) \z }mxs; | ||
| 1001 | ($val) = $val =~ m{ \A (.*) \z }mxs; | ||
| 1002 | |||
| 1003 | if ($val eq '[') { | ||
| 1004 | $self->{$directive}{$key} = [ ] if !exists $self->{$directive}{$key}; | ||
| 1005 | return; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | return if $val eq ']'; | ||
| 1009 | |||
| 1010 | if (exists $self->{$directive}{$key}) { | ||
| 1011 | $self->{$directive}{$key} = [ $self->{$directive}{$key} ] | ||
| 1012 | if !ref $self->{$directive}{$key}; | ||
| 1013 | push @{$self->{$directive}{$key}}, $val; | ||
| 1014 | } | ||
| 1015 | else { | ||
| 1016 | $self->{$directive}{$key} = $val; | ||
| 1017 | } | ||
| 1018 | return; | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | =head1 SEE ALSO | ||
| 1022 | |||
| 1023 | L<Apache2::Controller> | ||
| 1024 | |||
| 1025 | L<Apache2::Controller::Methods/get_directive> | ||
| 1026 | |||
| 1027 | L<Apache2::Controller::Session> | ||
| 1028 | |||
| 1029 | L<Apache2::Module> | ||
| 1030 | |||
| 1031 | =head1 AUTHOR | ||
| 1032 | |||
| 1033 | Mark Hedges, C<hedges +(a t)- formdata.biz> | ||
| 1034 | |||
| 1035 | =head1 COPYRIGHT AND LICENSE | ||
| 1036 | |||
| 1037 | Copyright 2008-2010 Mark Hedges. CPAN: markle | ||
| 1038 | |||
| 1039 | This library is free software; you can redistribute it and/or modify | ||
| 1040 | it under the same terms as Perl itself. | ||
| 1041 | |||
| 1042 | This software is provided as-is, with no warranty | ||
| 1043 | and no guarantee of fitness | ||
| 1044 | for any particular purpose. | ||
| 1045 | |||
| 1046 | =cut | ||
| 1047 | |||
| 1048 | 1; | ||
| 1049 |