Hi all! I've been trying to make my TABOO 1.7 native, and since I use a lot of SimpleTaglibs, that takes a bit of effort. I've run into some problems, and I think I'm seeing bugs too. I really like the execution time ideas of the new SimpleTaglibs, that's really neat, so I'd like to get this working.
I have attached three patches to this email. These are patches against the trunk as it is now. The first turn-rtsub.diff, I think fixes a bug, since $rtsub is first assigned a value there, it can't be meaningful as it is. The second turns most of Moe's commented warns into AxKit::Debug statements. I think that's useful, at least they are useful to me now that I try to debug. I have assigned levels as I think is nice, but I don't know about that, really. Finally, there's a patch that turns die's into Axkit exceptions. That's more elegant, right? The patches are independent, so any of them can be applied. errors and debug will conflict in two places though, so they can't be applied cleanly, but should be trivial to fix. I haven't tested. That is, I have tested, but since I can't get the new code in there to work, no guarantees here. Finally, I think there is something wrong in end_element: $longtag is found on line 813, but gets no value before it is first used on line 848. Now, it is Moe-magic, but still... It doesn't work for me... Perhaps people wants to have a look? Friendly Tiddely-pom, Kjetil -- Kjetil Kjernsmo Programmer / Astrophysicist / Ski-orienteer / Orienteer / Mountaineer [EMAIL PROTECTED] Homepage: http://www.kjetil.kjernsmo.net/ OpenPGP KeyID: 6A6A0BBC
Index: trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm =================================================================== --- trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (revision 351979) +++ trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (working copy) @@ -19,6 +19,7 @@ require 5.006; use strict; use Apache::AxKit::Language::XSP; +use AxKit; use Data::Dumper; eval { require WeakRef; }; eval { require XML::Smart; }; @@ -62,7 +63,7 @@ (my ($type, $token, $next) = ($spec =~ m/^([!\&[EMAIL PROTECTED])([^ {}]+)(.|$)/)) || die("childStruct specification invalid. Parse error at: '$spec'"); substr($spec,0,length($token)+1+($type?1:0)) = ''; - #warn("type: $type, token: $token, next: $next, spec: $spec"); + AxKit::Debug(9, "[STL] type: $type, token: $token, next: $next, spec: $spec"); my ($realtoken, $params); if ((($realtoken,$params) = ($token =~ m/^([^\(]+)((?:\([^ \)]+\))+)$/))) { my $i = 0; @@ -127,7 +128,7 @@ $handlerAttributes{$sub} ||= {}; my $handlerAttributes = $handlerAttributes{$sub}; foreach my $a (@attr) { - #warn("attr: $a"); + AxKit::Debug(10, "[STL] attr: $a"); my ($attr,$param) = ($a =~ m/([^(]*)(?:\((.*)\))?$/); my $warn = 0; $attr =~ s/^XSP_// || $warn++; @@ -184,12 +185,12 @@ } } elsif ($attr eq 'childStruct') { my $spec = $param[0]; - #warn("parsing $spec"); + AxKit::Debug(9, "[STL] parsing $spec"); $spec =~ s/\s+/ /g; $spec =~ s/ ?{ ?/{/g; $spec =~ s/ ?} ?/}/g; $$handlerAttributes{'struct'} = parseChildStructSpec($spec,{}); - #warn("parsed $param[0], got ".serializeChildStructSpec($$handlerAttributes{'struct'})); + AxKit::Debug(7, "[STL] parsed $param[0], got ".serializeChildStructSpec($$handlerAttributes{'struct'})); die("childStruct parse error") unless $$handlerAttributes{'struct'}; } elsif ($attr eq 'keepWhitespace') { $$handlerAttributes{'keepWS'} = 1; @@ -204,7 +205,7 @@ push @rest, $a; $warn = 0; } - warn("Please prefix your XSP attributes with 'XSP_' (${pkg}::${sub} : $attr)") if $warn; + AxKit::Debug(2, "[STL] Please prefix your XSP attributes with 'XSP_' (${pkg}::${sub} : $attr)") if $warn; } delete $handlerAttributes{$sub} if not keys %$handlerAttributes; return @rest; @@ -264,7 +265,7 @@ sub import { my $pkg = caller; - #warn("making $pkg a SimpleTaglib"); + AxKit::Debug(5, "[STL] making $pkg a SimpleTaglib"); { no strict 'refs'; *{$pkg.'::Handlers::MODIFY_CODE_ATTRIBUTES'} = \&MODIFY_CODE_ATTRIBUTES; @@ -370,7 +371,7 @@ my $desc = $$structStack[0][0]{'sub'}{$tag}; if (!$desc) { $desc = $$structStack[0][0]{'sub'}{'*'}; - #warn("$tag desc: ".Data::Dumper::Dumper($desc)); + #warn"[STL] $tag desc: ".Data::Dumper::Dumper($desc)); } die("Tag $tag not found in childStruct specification.") if (!$desc); push(@ignore, 1), return '' if ($$desc{'type'} eq '!'); @@ -637,7 +638,7 @@ my ($e, $element) = @_; my %attribs = map { $_->{'Name'} => $_->{'Value'} } @{$element->{'Attributes'}}; my $tag = $element->{'Name'}; - #warn("Element: ".join(",",map { "$_ => ".$$element{$_} } keys %$element)); + AxKit::Debug(7, "[STL] Element: ".join(",",map { "$_ => ".$$element{$_} } keys %$element)); my $ns = $element->{'NamespaceURI'}; my $frame = ($frame{$ns} ||= []); $structStack = ($structStack{$ns} ||= []); @@ -646,9 +647,9 @@ my ($sub, $subOpen, $rtsub, $rtsubOpen); my $attribs = {}; my $longtag; - #warn("full struct: ".serializeChildStructSpec($$structStack[0][$#{$$structStack[0]}]{'sub'})) if $$structStack[0]; - #warn("current node: ".$$structStack[0][0]{'name'}) if $$structStack[0]; - #warn("rest struct: ".serializeChildStructSpec($$structStack[0][0]{'sub'})) if $$structStack[0]; + AxKit::Debug(10, "[STL] full struct: ".serializeChildStructSpec($$structStack[0][$#{$$structStack[0]}]{'sub'})) if $$structStack[0]; + AxKit::Debug(10, "[STL] current node: ".$$structStack[0][0]{'name'}) if $$structStack[0]; + AxKit::Debug(10, "[STL] rest struct: ".serializeChildStructSpec($$structStack[0][0]{'sub'})) if $$structStack[0]; if ($$structStack[0][0]{'param'} && exists $$structStack[0][0]{'param'}{$tag}) { $sub = \&set_childStruct_value; $subOpen = \&set_childStruct_value__open; @@ -670,27 +671,29 @@ } else { for my $i (0..$#{$frame}) { if (exists $$frame[$i]{'vars'}{$tag}) { - #warn("variable: $tag"); + AxKit::Debug(9, "[STL] variable: $tag"); $sub = \&set_attribOrChild_value; $subOpen = \&set_attribOrChild_value__open; last; } } + AxKit::Debug(10, "[STL] sub: $sub"); if (!$sub) { my @backframes = (reverse(map{ ${$_}{'name'} } @{$frame}),$tag); - #warn("frames: "[EMAIL PROTECTED]", backframes: ".join(",",@backframes)); + AxKit::Debug(9, "[STL] frames: "[EMAIL PROTECTED]", backframes: ".join(",",@backframes)); my $i = @backframes+1; while ($i) { $longtag = join('___', @backframes) || '_default'; shift @backframes; $i--; - #warn("checking for $longtag"); + AxKit::Debug(8, "[STL] checking for $longtag"); if ($sub = $pkg->can(makeVariableName($longtag))) { $subOpen = $pkg->can(makeVariableName($longtag)."__open"); } if ($handlerAttributes{$rtsub} and $rtsub = $rtpkg->can(makeVariableName($longtag))) { $rtsubOpen = $rtpkg->can(makeVariableName($longtag)."__open"); } + AxKit::Debug(10, "sub: $sub; rtsub: $rtsub"); die("Simultaneous run-time and compile-time handlers for one tag not supported") if $sub and $rtsub; last if $sub or $rtsub; } @@ -845,6 +848,7 @@ } $$attribs{$$handlerAttributes{'resultparam'}} = makeSingleQuoted($$attribs{$$handlerAttributes{'resultparam'}}) if $$handlerAttributes{'resultparam'}; + AxKit::Debug(9, "Appending execution time call to ${rtpkg}::".makeVariableName($longtag)); $e->append_to_script("${rtpkg}::".makeVariableName($longtag)."(".makeSingleQuoted($tag).",{".join(",",map { makeSingleQuoted($_)."=>".$$attribs{$_} } keys %$attribs).'},$'.makeVariableName($rtpkg)."_stack,".($$handlerAttributes{'smart'}?'$xml_subtree':'undef').");"); } @@ -937,7 +941,7 @@ shift @{$stackcur{$rtpkg}}; $e->append_to_script('$'.makeVariableName($rtpkg).'_stack = $'.makeVariableName($rtpkg).'_stack['.$stackcur{$rtpkg}[0]."];\n"); } - #warn('script len: '.length($e->{XSP_Script}).', end tag: '.$tag); + AxKit::Debug(9, '[STL] script len: '.length($e->{XSP_Script}).', end tag: '.$tag); return ''; }
Index: trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm =================================================================== --- trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (revision 351979) +++ trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (working copy) @@ -20,6 +20,7 @@ use strict; use Apache::AxKit::Language::XSP; use Data::Dumper; +use Apache::AxKit::Exception; eval { require WeakRef; }; eval { require XML::Smart; }; use attributes; @@ -60,7 +61,7 @@ while (length($spec)) { $spec = substr($spec,1), return $result if (substr($spec,0,1) eq '}'); (my ($type, $token, $next) = ($spec =~ m/^([!\&[EMAIL PROTECTED])([^ {}]+)(.|$)/)) - || die("childStruct specification invalid. Parse error at: '$spec'"); + || throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. Parse error at: '$spec'"); substr($spec,0,length($token)+1+($type?1:0)) = ''; #warn("type: $type, token: $token, next: $next, spec: $spec"); my ($realtoken, $params); @@ -71,21 +72,21 @@ } if ($type eq '&') { ($$result{$token} = $$refs{$token}) - || die("childStruct specification invalid. '&' reference not found."); - die("childStruct specification invalid. '&' cannot be used on '*' nodes.") + || throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '&' reference not found."); + throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '&' cannot be used on '*' nodes.") if ($$result{$token}{'type'} eq '*'); - die("childStruct specification invalid. '&' may only take a reference.") + throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '&' may only take a reference.") if $$result{'param'}; eval { WeakRef::weaken($$result{$token}) }; return $result if (!$next || $next eq '}'); next; } $$result{$token}{'type'} = $type || '$'; - die("childStruct specification invalid. '${type}' cannot be used with '{'.") + throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '${type}' cannot be used with '{'.") if ($next eq '{' and ($type eq '*' || $type eq '!')); - die("childStruct specification invalid. '${type}' cannot be used with '(,,,)'.") + throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '${type}' cannot be used with '(,,,)'.") if ($$result{$token}{'param'} and ($type eq '*' || $type eq '!')); - die("childStruct specification invalid. '**' is not supported.") + throw Apache::AxKit::Exception::Error(-text => "childStruct specification invalid. '**' is not supported.") if ($token eq '*' and $type eq '*'); $$result{''}{'name'} = $token if ($type eq '*'); $$result{$token}{'name'} = $token; @@ -190,7 +191,7 @@ $spec =~ s/ ?} ?/}/g; $$handlerAttributes{'struct'} = parseChildStructSpec($spec,{}); #warn("parsed $param[0], got ".serializeChildStructSpec($$handlerAttributes{'struct'})); - die("childStruct parse error") unless $$handlerAttributes{'struct'}; + throw Apache::AxKit::Exception::Error(-text => "childStruct parse error") unless $$handlerAttributes{'struct'}; } elsif ($attr eq 'keepWhitespace') { $$handlerAttributes{'keepWS'} = 1; } elsif ($attr eq 'captureContent') { @@ -372,7 +373,7 @@ $desc = $$structStack[0][0]{'sub'}{'*'}; #warn("$tag desc: ".Data::Dumper::Dumper($desc)); } - die("Tag $tag not found in childStruct specification.") if (!$desc); + throw Apache::AxKit::Exception::Error(-text => "Tag $tag not found in childStruct specification.") if (!$desc); push(@ignore, 1), return '' if ($$desc{'type'} eq '!'); push @ignore, 0; unshift @{$$structStack[0]},$desc; @@ -553,12 +554,12 @@ $parent->appendChild($data); next; } - die 'data is not a hash ref or DOM fragment!' unless ref($data) eq 'HASH'; + throw Apache::AxKit::Exception::Error(-text => 'data is not a hash ref or DOM fragment!') unless ref($data) eq 'HASH'; while (my ($key, $val) = each %$data) { my $outer_namespaces_added = 0; if (substr($key,0,1) eq '@') { $key = substr($key,1); - die 'attribute value is not a simple scalar!' if ref($val); + throw Apache::AxKit::Exception::Error(-text => 'attribute value is not a simple scalar!') if ref($val); next if $key =~ m/^xmlns(?::|$)/; # already processed these my ($ns, $prefix, $name) = parse_namespace($key); #$prefix = _lookup_prefix($ns, $namespaces) if $ns and not $prefix; @@ -691,7 +692,7 @@ if ($handlerAttributes{$rtsub} and $rtsub = $rtpkg->can(makeVariableName($longtag))) { $rtsubOpen = $rtpkg->can(makeVariableName($longtag)."__open"); } - die("Simultaneous run-time and compile-time handlers for one tag not supported") if $sub and $rtsub; + throw Apache::AxKit::Exception::Error(-text => "Simultaneous run-time and compile-time handlers for one tag not supported") if $sub and $rtsub; last if $sub or $rtsub; } } @@ -700,7 +701,7 @@ $sub = &set_XmlSmart_value; $subOpen = &set_XmlSmart_value__open; } - die "invalid tag: $tag (namespace: $ns, package $pkg, parents ".join(", ",map{ ${$_}{'name'} } @{$frame}).")" unless $sub or $rtsub; + throw Apache::AxKit::Exception::Error(-text => "invalid tag: $tag (namespace: $ns, package $pkg, parents ".join(", ",map{ ${$_}{'name'} } @{$frame}).")") unless $sub or $rtsub; my $handlerAttributes = $handlerAttributes{$sub || $rtsub}; if ($$handlerAttributes{'compile'}) { @@ -813,7 +814,7 @@ my $longtag; my $sub = $$frame[0]{'sub'}; my $rtsub = $$frame[0]{'rtsub'}; - die "invalid closing tag: $tag (namespace: $ns, package $pkg, sub ".makeVariableName($tag).")" unless $sub or $rtsub; + throw Apache::AxKit::Exception::Error(-text => "invalid closing tag: $tag (namespace: $ns, package $pkg, sub ".makeVariableName($tag).")") unless $sub or $rtsub; my $handlerAttributes = $handlerAttributes{$sub || $rtsub}; if ($globalframe[0]{'capture'}) {
Index: trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm =================================================================== --- trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (revision 349818) +++ trunk/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm (working copy) @@ -688,7 +688,7 @@ if ($sub = $pkg->can(makeVariableName($longtag))) { $subOpen = $pkg->can(makeVariableName($longtag)."__open"); } - if ($handlerAttributes{$rtsub} and $rtsub = $rtpkg->can(makeVariableName($longtag))) { + if (($rtsub = $rtpkg->can(makeVariableName($longtag))) && $handlerAttributes{$rtsub}) { $rtsubOpen = $rtpkg->can(makeVariableName($longtag)."__open"); } die("Simultaneous run-time and compile-time handlers for one tag not supported") if $sub and $rtsub;
pgppHrCWVjr2o.pgp
Description: PGP signature