| 1 | package AxKit::XSP::Cookie; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 0 | ▶ | use Apache::AxKit::Language::XSP; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 4 | use Apache::Cookie; | ||
| 5 | |||
| 6 | use vars qw/@ISA $NS $VERSION/; | ||
| 7 | |||
| 8 | @ISA = ('Apache::AxKit::Language::XSP'); | ||
| 9 | $NS = 'http://axkit.org/NS/xsp/cookie/v1'; | ||
| 10 | |||
| 11 | $VERSION = "1.41"; | ||
| 12 | |||
| 13 | ## Taglib subs | ||
| 14 | |||
| 15 | # NONE! ;-) | ||
| 16 | |||
| 17 | my $cookie_context = ''; | ||
| 18 | |||
| 19 | ## Parser subs | ||
| 20 | |||
| 21 | sub parse_start { | ||
| 22 | my ($e, $tag, %attribs) = @_; | ||
| 23 | #warn "Checking: $tag\n"; | ||
| 24 | |||
| 25 | if ($tag eq 'create') { | ||
| 26 | $cookie_context = 'create'; | ||
| 27 | my $code = '{ my $__cookie = Apache::Cookie->new($r);'; | ||
| 28 | |||
| 29 | if ($attribs{name}) { | ||
| 30 | $code .= '$__cookie->name(q|' . $attribs{name} . '|);'; | ||
| 31 | } | ||
| 32 | if ($attribs{value}) { | ||
| 33 | $code .= '$__cookie->value(q|' . $attribs{value} . '|);'; | ||
| 34 | } | ||
| 35 | if ($attribs{domain}) { | ||
| 36 | $code .= '$__cookie->domain(q|' . $attribs{domain} . '|);'; | ||
| 37 | } | ||
| 38 | if ($attribs{path}) { | ||
| 39 | $code .= '$__cookie->path(q|' . $attribs{path} . '|);'; | ||
| 40 | } | ||
| 41 | if ($attribs{secure}) { | ||
| 42 | $code .= '$__cookie->secure(q|' . $attribs{secure} . '|);'; | ||
| 43 | } | ||
| 44 | if ($attribs{expires}) { | ||
| 45 | $code .= '$__cookie->expires(q|' . $attribs{expires} . '|);'; | ||
| 46 | } | ||
| 47 | |||
| 48 | return $code; | ||
| 49 | } | ||
| 50 | elsif ($tag eq 'name') { | ||
| 51 | if ($cookie_context eq 'create') { | ||
| 52 | return '$__cookie->name(""'; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | elsif ($tag eq 'value') { | ||
| 56 | return '$__cookie->value(""'; | ||
| 57 | } | ||
| 58 | elsif ($tag eq 'domain') { | ||
| 59 | return '$__cookie->domain(""'; | ||
| 60 | } | ||
| 61 | elsif ($tag eq 'expires') { | ||
| 62 | return '$__cookie->expires(""'; | ||
| 63 | } | ||
| 64 | elsif ($tag eq 'path') { | ||
| 65 | return '$__cookie->path(""'; | ||
| 66 | } | ||
| 67 | elsif ($tag eq 'secure') { | ||
| 68 | return '$__cookie->secure(""'; | ||
| 69 | } | ||
| 70 | elsif ($tag eq 'fetch') { | ||
| 71 | $cookie_context = 'fetch'; | ||
| 72 | $e->start_expr($tag); | ||
| 73 | my $code = 'my (%__cookies, $__cookie, $__cookie_name);' . "\n"; | ||
| 74 | $code .= '%__cookies = Apache::Cookie->fetch;'; | ||
| 75 | $code .= '$__cookie_name = ""'; | ||
| 76 | if ($attribs{name}) { | ||
| 77 | $code .= '. q|' . $attribs{name} . '|;'; | ||
| 78 | $code .= '$__cookie = $__cookies{$__cookie_name} || Apache::Cookie->new($r);'; | ||
| 79 | } | ||
| 80 | return $code; | ||
| 81 | } | ||
| 82 | else { | ||
| 83 | die "Unknown cookie tag: $tag"; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | sub parse_char { | ||
| 89 | my ($e, $text) = @_; | ||
| 90 | $text =~ s/^\s*//; | ||
| 91 | $text =~ s/\s*$//; | ||
| 92 | |||
| 93 | return '' unless $text; | ||
| 94 | |||
| 95 | $text =~ s/\|/\\\|/g; | ||
| 96 | return ". q|$text|"; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | sub parse_end { | ||
| 101 | my ($e, $tag) = @_; | ||
| 102 | |||
| 103 | if ($tag eq 'create') { | ||
| 104 | $cookie_context = ''; | ||
| 105 | return '$__cookie->bake;}' . "\n"; | ||
| 106 | } | ||
| 107 | elsif ($tag eq 'name') { | ||
| 108 | if ($cookie_context eq 'create') { | ||
| 109 | return ');'; | ||
| 110 | } | ||
| 111 | else { | ||
| 112 | return ';$__cookie = $__cookies{$__cookie_name} || Apache::Cookie->new($r);'; | ||
| 113 | |||
| 114 | } | ||
| 115 | } | ||
| 116 | elsif ($tag eq 'value') { | ||
| 117 | if ($cookie_context eq 'create') { | ||
| 118 | return ');'; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | elsif ($tag eq 'expires') { | ||
| 122 | if ($cookie_context eq 'create') { | ||
| 123 | return ');'; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | elsif ($tag eq 'domain') { | ||
| 127 | if ($cookie_context eq 'create') { | ||
| 128 | return ');'; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | elsif ($tag eq 'path') { | ||
| 132 | if ($cookie_context eq 'create') { | ||
| 133 | return ');'; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | elsif ($tag eq 'secure') { | ||
| 137 | if ($cookie_context eq 'create') { | ||
| 138 | return ');'; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | elsif ($tag eq 'fetch') { | ||
| 142 | $cookie_context = ''; | ||
| 143 | $e->append_to_script('$__cookie->value;'); | ||
| 144 | $e->end_expr; | ||
| 145 | return ''; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | sub parse_comment { | ||
| 150 | # compat only | ||
| 151 | } | ||
| 152 | |||
| 153 | sub parse_final { | ||
| 154 | # compat only | ||
| 155 | } | ||
| 156 | |||
| 157 | 1; | ||
| 158 | |||
| 159 | __END__ | ||