Commit 651474ff62b4d928a4431a9d680d0f2190298374
- Diff rendering mode:
- inline
- side by side
lib/HTTP/Config.pm
(31 / 6)
|   | |||
| 208 | 208 | } | |
| 209 | 209 | @m = sort { $b->{_order} cmp $a->{_order} } @m; | |
| 210 | 210 | delete $_->{_order} for @m; | |
| 211 | return @m; | ||
| 211 | return @m if wantarray; | ||
| 212 | return $m[0]; | ||
| 212 | 213 | } | |
| 213 | 214 | ||
| 214 | 215 | sub add_item { | |
| … | … | ||
| 234 | 234 | ||
| 235 | 235 | =head1 NAME | |
| 236 | 236 | ||
| 237 | HTTP::Config - | ||
| 237 | HTTP::Config - Configuration for request and response objects | ||
| 238 | 238 | ||
| 239 | 239 | =head1 SYNOPSIS | |
| 240 | 240 | ||
| 241 | 241 | use HTTP::Config; | |
| 242 | my $c = HTTP::Config->new; | ||
| 243 | $c->add(m_domain => ".example.com", m_scheme => "http", verbose => 1); | ||
| 244 | |||
| 245 | use HTTP::Request; | ||
| 246 | my $request = HTTP::Request->new(GET => "http://www.example.com"); | ||
| 247 | |||
| 248 | if (my @m = $c->matching($request)) { | ||
| 249 | print "Yadayada\n" if $m[0]->{verbose}; | ||
| 250 | } | ||
| 242 | 251 | ||
| 243 | 252 | =head1 DESCRIPTION | |
| 244 | 253 | ||
| 245 | An C<HTTP::Config> object is basically a list of entries (hashes) that | ||
| 246 | can be matched against requests or request/response pairs. It's | ||
| 254 | An C<HTTP::Config> object is a list of entries that | ||
| 255 | can be matched against request or request/response pairs. Its | ||
| 247 | 256 | purpose is to hold configuration data that can be looked up given a | |
| 248 | 257 | request or response object. | |
| 249 | 258 | ||
| … | … | ||
| 266 | 266 | ||
| 267 | 267 | =item $conf = HTTP::Config->new | |
| 268 | 268 | ||
| 269 | Constructor | ||
| 269 | Constructs a new empty C<HTTP::Config> object and returns it. | ||
| 270 | 270 | ||
| 271 | 271 | =item $conf->entries | |
| 272 | 272 | ||
| 273 | 273 | Returns the list of entries in the configuration object. | |
| 274 | In scalar context returns the number of entries. | ||
| 274 | 275 | ||
| 275 | 276 | =item $conf->empty | |
| 276 | 277 | ||
| 277 | 278 | Return true if there are no entries in the configuration object. | |
| 279 | This is just a shorthand for C<< not $conf->entries >>. | ||
| 278 | 280 | ||
| 279 | 281 | =item $conf->add( %matchspec, %other ) | |
| 280 | 282 | ||
| 281 | 283 | =item $conf->add( \%entry ) | |
| 282 | 284 | ||
| 283 | 285 | Adds a new entry to the configuration. | |
| 286 | You can either pass separate key/value pairs or a hash reference. | ||
| 284 | 287 | ||
| 285 | 288 | =item $conf->remove( %spec ) | |
| 286 | 289 | ||
| 287 | Removes (and returns) the entries that match. | ||
| 290 | Removes (and returns) the entries that have matches for all the key/value pairs in %spec. | ||
| 291 | If %spec is empty this will match all entries; so it will empty the configuation object. | ||
| 288 | 292 | ||
| 289 | 293 | =item $conf->matching( $uri, $request, $response ) | |
| 290 | 294 | ||
| … | … | ||
| 300 | 300 | ||
| 301 | 301 | Returns the entries that match the given $uri, $request and $response triplet. | |
| 302 | 302 | ||
| 303 | If called with a single $request object then the $uri is obtained by calling its 'uri_canonical' method. | ||
| 304 | If called with a single $response object, then the request object is obtained by calling its 'request' method; | ||
| 305 | and then the $uri is obtained as if a single $request was provided. | ||
| 306 | |||
| 303 | 307 | The entries are returned with the most specific matches first. | |
| 308 | In scalar context returns the most specific match or C<undef> in none match. | ||
| 304 | 309 | ||
| 305 | 310 | =item $conf->add_item( $item, %matchspec ) | |
| 306 | 311 | ||
| … | … | ||
| 323 | 323 | of these you can provide an array of values instead of a single value. | |
| 324 | 324 | The entry matches if at least one of the values in the array matches. | |
| 325 | 325 | ||
| 326 | Entries that require match against a response object attribute will never match | ||
| 327 | unless a response object was provided. | ||
| 328 | |||
| 326 | 329 | =over | |
| 327 | 330 | ||
| 328 | 331 | =item m_scheme => $scheme | |
| … | … | ||
| 395 | 395 | =item m_media_type => "text/html" | |
| 396 | 396 | ||
| 397 | 397 | Matches if the response media type matches. | |
| 398 | |||
| 399 | With a value of "html" matches if $response->content_is_html returns TRUE. | ||
| 400 | With a value of "xhtml" matches if $response->content_is_xhtml returns TRUE. | ||
| 398 | 401 | ||
| 399 | 402 | =item m_uri__I<$method> => undef | |
| 400 | 403 |

