| blib/lib/AxKit/XSP/AttrParam.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 9 | 9 | 100.0 |
| branch | n/a | ||
| condition | n/a | ||
| subroutine | 3 | 3 | 100.0 |
| pod | n/a | ||
| total | 12 | 12 | 100.0 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | |||||||
| 2 | ### | ||||||
| 3 | # AxKit XSP taglib for HTTP request parameters | ||||||
| 4 | # Robin Berjon |
||||||
| 5 | # 03/05/2001 - v.0.01 | ||||||
| 6 | ### | ||||||
| 7 | |||||||
| 8 | package AxKit::XSP::AttrParam; | ||||||
| 9 | 1 | 1 | 577 | use strict; | |||
| 1 | 2 | ||||||
| 1 | 28 | ||||||
| 10 | 1 | 1 | 5 | use vars qw($VERSION $NS $IN_NAME); | |||
| 1 | 1 | ||||||
| 1 | 71 | ||||||
| 11 | $VERSION = '0.01'; | ||||||
| 12 | |||||||
| 13 | 1 | 1 | 4 | use base qw(Apache::AxKit::Language::XSP); | |||
| 1 | 5 | ||||||
| 1 | 1537 | ||||||
| 14 | |||||||
| 15 | # define the namespace we use (RDDL there one of these days) | ||||||
| 16 | $NS = 'http://xmlns.knowscape.com/xsp/AttrParam'; | ||||||
| 17 | $IN_NAME = 0; | ||||||
| 18 | |||||||
| 19 | #---> Parser subs <-------------------------------------------------# | ||||||
| 20 | |||||||
| 21 | sub parse_start { | ||||||
| 22 | my $e = shift; | ||||||
| 23 | my $tag = shift; | ||||||
| 24 | my %attr = @_; | ||||||
| 25 | |||||||
| 26 | my $code; | ||||||
| 27 | if ($tag eq 'param') { | ||||||
| 28 | $e->start_expr($tag); | ||||||
| 29 | $code = 'my $name; '; | ||||||
| 30 | if (exists $attr{name}) { | ||||||
| 31 | $attr{name} =~ s/"/\\"/; | ||||||
| 32 | $code .= '$name = "' . $attr{name} . '"; '; | ||||||
| 33 | } | ||||||
| 34 | } | ||||||
| 35 | elsif ($tag eq 'name') { | ||||||
| 36 | $IN_NAME = 1; | ||||||
| 37 | $code = '$name = "" '; | ||||||
| 38 | } | ||||||
| 39 | $e->append_to_script($code); | ||||||
| 40 | |||||||
| 41 | return ''; | ||||||
| 42 | } | ||||||
| 43 | |||||||
| 44 | sub parse_end { | ||||||
| 45 | my $e = shift; | ||||||
| 46 | my $tag = shift; | ||||||
| 47 | |||||||
| 48 | if ($tag eq 'param') { | ||||||
| 49 | $e->append_to_script('$cgi->param($name); '); | ||||||
| 50 | $e->end_expr(); | ||||||
| 51 | } | ||||||
| 52 | elsif ($tag eq 'name') { | ||||||
| 53 | $e->append_to_script(';'); | ||||||
| 54 | $IN_NAME = 0; | ||||||
| 55 | } | ||||||
| 56 | return ''; | ||||||
| 57 | } | ||||||
| 58 | |||||||
| 59 | sub parse_char { | ||||||
| 60 | return unless $IN_NAME; | ||||||
| 61 | my $e = shift; | ||||||
| 62 | my $txt = shift; | ||||||
| 63 | |||||||
| 64 | $txt =~ s/"/\\"/; | ||||||
| 65 | $e->append_to_script(' . "' . $txt . '"'); | ||||||
| 66 | return ''; | ||||||
| 67 | } | ||||||
| 68 | sub parse_comment {} | ||||||
| 69 | sub parse_final {} | ||||||
| 70 | |||||||
| 71 | 1; | ||||||
| 72 | |||||||
| 73 | #---> The End <-----------------------------------------------------# | ||||||
| 74 | |||||||
| 75 | =pod | ||||||
| 76 | |||||||
| 77 | =head1 NAME | ||||||
| 78 | |||||||
| 79 | AxKit::XSP::AttrParam - XSP taglib for HTTP request parameters | ||||||
| 80 | |||||||
| 81 | =head1 SYNOPSIS | ||||||
| 82 | |||||||
| 83 | Add the aprm: namespace to your XSP C< |
||||||
| 84 | |||||||
| 85 | | ||||||
| 86 | language='Perl' | ||||||
| 87 | xmlns:xsp='http://apache.org/xsp/core/v1' | ||||||
| 88 | xmlns:aprm='http://xmlns.knowscape.com/xsp/AttrParam'> | ||||||
| 89 | |||||||
| 90 | And add the taglib to AxKit (via httpd.conf or .htaccess): | ||||||
| 91 | |||||||
| 92 | AxAddXSPTaglib AxKit::XSP::AttrParam | ||||||
| 93 | |||||||
| 94 | =head1 DESCRIPTION | ||||||
| 95 | |||||||
| 96 | The XSP aprm: tag library implements a simple way to access HTTP | ||||||
| 97 | request parameters (query string and posted form data) by field name. | ||||||
| 98 | it is shamelessly stolen from Kip Hampton's AxKit::XSP::Param but | ||||||
| 99 | allows one to use parameter names that may not be valid XML names, as | ||||||
| 100 | well as parametre names derived from expressions. | ||||||
| 101 | |||||||
| 102 | Thus, the B |
||||||
| 103 | |||||||
| 104 | |||||||
| 105 | |||||||
| 106 | is available after submitting the form either as | ||||||
| 107 | |||||||
| 108 | |
||||||
| 109 | |||||||
| 110 | or as | ||||||
| 111 | |||||||
| 112 | |
||||||
| 113 | |
||||||
| 114 | |||||||
| 115 | |||||||
| 116 | or yet again (and more usefully) | ||||||
| 117 | |||||||
| 118 | |
||||||
| 119 | |
||||||
| 120 | |||||||
| 121 | |||||||
| 122 | =head2 Tag Reference | ||||||
| 123 | |||||||
| 124 | There are no named functions for this tag library. | ||||||
| 125 | |||||||
| 126 | =head1 ACKNOWLEDGEMENTS | ||||||
| 127 | |||||||
| 128 | Special thanks to Matt and Kip from the entire Knowscape dev team. | ||||||
| 129 | |||||||
| 130 | =head1 AUTHOR | ||||||
| 131 | |||||||
| 132 | Robin Berjon, | ||||||
| 133 | |||||||
| 134 | =head1 COPYRIGHT | ||||||
| 135 | |||||||
| 136 | Copyright (c) 2001 Robin Berjon. All rights reserved. This program is | ||||||
| 137 | free software; you can redistribute it and/or modify it under the same | ||||||
| 138 | terms as Perl itself. | ||||||
| 139 | |||||||
| 140 | =cut |