| 1 | ############################################################################### | ||
| 2 | # XML::Template::Element::Block | ||
| 3 | # | ||
| 4 | # Copyright (c) 2002-2003 Jonathan A. Waxman <jowaxman@law.upenn.edu> | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or | ||
| 8 | # modify it under the same terms as Perl itself. | ||
| 9 | ############################################################################### | ||
| 10 | package XML::Template::Element::Block; | ||
| 11 | use base qw(XML::Template::Element::DB); | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use XML::Template::Element::DB; | ||
| 15 | |||
| 16 | |||
| 17 | =pod | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | XML::Template::Element::Block - XML::Template plugin module for the block | ||
| 22 | namespace tagset. | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | This XML::Template plugin module implements the block namespace tagset. | ||
| 27 | The block namespace includes tags that handle XHTML blocks stored in a | ||
| 28 | database. | ||
| 29 | |||
| 30 | =head1 CONSTRUCTOR | ||
| 31 | |||
| 32 | XML::Template::Element::Block inherits its constructor method, C<new>, | ||
| 33 | from L<XML::Template::Element>. | ||
| 34 | |||
| 35 | =head1 BLOCK TAGSET METHODS | ||
| 36 | |||
| 37 | =head2 include | ||
| 38 | |||
| 39 | This method implements the include element. It reads an XHTML block from | ||
| 40 | a database table and parses it. The following attributes are used: | ||
| 41 | |||
| 42 | =over 4 | ||
| 43 | |||
| 44 | =item name | ||
| 45 | |||
| 46 | The name of the XHTML block to load. | ||
| 47 | |||
| 48 | =back | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | sub include { | ||
| 53 | my $self = shift; | ||
| 54 | my ($code, $attribs) = @_; | ||
| 55 | |||
| 56 | # Create attribute param code; | ||
| 57 | my $attribs_named_params = $self->generate_named_params ($attribs); | ||
| 58 | |||
| 59 | my $name = $self->get_attrib ($attribs, 'name') || 'undef'; | ||
| 60 | |||
| 61 | my $outcode = qq! | ||
| 62 | do { | ||
| 63 | use XML::Template::Element::Block::Load; | ||
| 64 | |||
| 65 | \$vars->create_context (); | ||
| 66 | my \%attribs = ($attribs_named_params); | ||
| 67 | |||
| 68 | my \$cgi_header = \$process->{_cgi_header}; | ||
| 69 | \$process->{_cgi_header} = 0; | ||
| 70 | my \$value; | ||
| 71 | my \$io = IO::String->new (\$value); | ||
| 72 | my \$ofh = select \$io; | ||
| 73 | $code | ||
| 74 | select \$ofh; | ||
| 75 | \$vars->set ('_content' => \$value); | ||
| 76 | \$process->{_cgi_header} = \$cgi_header; | ||
| 77 | |||
| 78 | my \%vars; | ||
| 79 | while (my (\$attrib, \$value) = each \%attribs) { | ||
| 80 | my (\$attrib_namespace, \$attrib_name); | ||
| 81 | if (\$attrib =~ /^{([^}]+)}(.*)\$/) { | ||
| 82 | \$attrib_namespace = \$1; | ||
| 83 | \$attrib_name = \$2; | ||
| 84 | } else { | ||
| 85 | \$attrib_namespace = ''; | ||
| 86 | \$attrib_name = \$attrib; | ||
| 87 | } | ||
| 88 | \$vars{\$attrib_name} = \$value; | ||
| 89 | } | ||
| 90 | |||
| 91 | my \%loaded = \$process->get_load (); | ||
| 92 | my \%tloaded; | ||
| 93 | while (my (\$module, \$loaded) = each \%loaded) { | ||
| 94 | if (\$module =~ /Cache/) { | ||
| 95 | \$tloaded{\$module} = \$loaded; | ||
| 96 | } else { | ||
| 97 | \$tloaded{\$module} = 0; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | \$tloaded{'XML::Template::Element::Block::Load'} = 1; | ||
| 101 | \$process->set_load (\%tloaded); | ||
| 102 | # XXX not sure why i did this, but now errors aren't detected here... | ||
| 103 | if (ref (\$ofh) eq 'IO::String') { | ||
| 104 | \$process->process ($name, \\\%vars); | ||
| 105 | } else { | ||
| 106 | \$process->process ($name, \\\%vars) || die \$process->error; | ||
| 107 | } | ||
| 108 | \$process->set_load (\%loaded); | ||
| 109 | |||
| 110 | \$vars->delete_context (); | ||
| 111 | }; | ||
| 112 | !; | ||
| 113 | |||
| 114 | return $outcode; | ||
| 115 | } | ||
| 116 | |||
| 117 | =pod | ||
| 118 | |||
| 119 | =head1 SQL TAGSET METHODS | ||
| 120 | |||
| 121 | XML::Template::Element::Block is a subclass of | ||
| 122 | L<XML::Template::Element::DB>, so derives the SQL tagset. See | ||
| 123 | L<XML::Template::Element::DB> for more details. | ||
| 124 | |||
| 125 | =head1 AUTHOR | ||
| 126 | |||
| 127 | Jonathan Waxman | ||
| 128 | <jowaxman@bbl.med.upenn.edu> | ||
| 129 | |||
| 130 | =head1 COPYRIGHT | ||
| 131 | |||
| 132 | Copyright (c) 2002-2003 Jonathan A. Waxman | ||
| 133 | All rights reserved. | ||
| 134 | |||
| 135 | This program is free software; you can redistribute it and/or | ||
| 136 | modify it under the same terms as Perl itself. | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 | 1; |