[CDBI] Adding behavior to Class::DBI::ToSax

[prev] [thread] [next] [Date index for 2006/02/01]

From: Eduardo Grosclaude
Subject: [CDBI] Adding behavior to Class::DBI::ToSax
Date: 19:28 on 01 Feb 2006
--===============0402174914==
Content-Type: multipart/alternative; 
	boundary="----=_Part_5717_25872284.1138822098579"

------=_Part_5717_25872284.1138822098579
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello Gentlemen,
Hope this is the proper place to discuss Class::DBI::ToSax. I have devised =
a
small patch to allow me to select which columns, and in which order, I will
have SAX events generated for. Seems to work for me. Would love to have
someone knowledgeable to tell me if this is of some public value.
Works by optionally giving your object a to_sax_columns method which return=
s
a reference to a list with desired columns and order. Should keep former
ToSax behavior if not defined.
Thank you in advance.

[oso@osobox xml]$ diff ToSax.pm ToSax.pm.orig
86,112c86,97
<         if( $self->can( 'to_sax_columns' ) ) {
<                 my %has_many =3D map { $_ =3D> 1 } @{ $self->_has_many_me=
thods
|| [] };
<                 foreach my $col ( @{ $self->to_sax_columns } ) {
<                         if( defined $has_a{ $col } ) {
<                             $self->_emit_sax_value( $handler, $col,
$self->$col, %opt,
<                                 wrapper =3D> $col );
<                         } elsif ( defined $has_many{ $col } ) {
<                                     $self->_emit_sax_value( $handler,
$col, $_, %opt )
<                                         foreach $self->$col;
<                         } else { # plain
<                             $self->_emit_sax_value( $handler, $col,
$self->$col, %opt );
<                         }
<                 }
<         } else {
<             foreach my $col ( sort @plain ) {
<                 $self->_emit_sax_value( $handler, $col, $self->$col, %opt
);
<             }
<
<             foreach my $col ( sort keys %has_a ) {
<                 $self->_emit_sax_value( $handler, $col, $self->$col, %opt=
,
<                     wrapper =3D> $col );
<             }
<
<             foreach my $col ( sort @{ $self->_has_many_methods || [] } ) =
{
<                 $self->_emit_sax_value( $handler, $col, $_, %opt )
<                     foreach $self->$col;
<             }
---
>         foreach my $col ( sort @plain ) {
>             $self->_emit_sax_value( $handler, $col, $self->$col, %opt );
>         }
>
>         foreach my $col ( sort keys %has_a ) {
>             $self->_emit_sax_value( $handler, $col, $self->$col, %opt,
>                 wrapper =3D> $col );
>         }
>
>         foreach my $col ( sort @{ $self->_has_many_methods || [] } ) {
>             $self->_emit_sax_value( $handler, $col, $_, %opt )
>                 foreach $self->$col;

--
Eduardo Grosclaude
Universidad Nacional del Comahue
Neuquen, Argentina

------=_Part_5717_25872284.1138822098579
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello Gentlemen,<br>Hope this is the proper place to discuss Class::DBI::To=
Sax. I have devised a small patch to allow me to select which columns, and =
in which order, I will have SAX events generated for. Seems to work for me.=
 Would love to have someone knowledgeable to tell me if this is of some pub=
lic value.
<br>Works by optionally giving your object a to_sax_columns method which re=
turns a reference to a list with desired columns and order. Should keep for=
mer ToSax behavior if not defined.<br>Thank you in advance.<br><br clear=3D=
"all">
[oso@osobox xml]$ diff ToSax.pm ToSax.pm.orig<br>86,112c86,97<br>&lt;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( $self-&gt;can( 'to_sax_colum=
ns' ) ) {<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %has_many =3D map { $_ =3D&gt; 1 =
} @{ $self-&gt;_has_many_methods || [] };<br>
&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; foreach my $col ( @{ $self-&gt;to_sax_columns } )=
 {<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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p;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; $self-&gt;_emit_sax_value( $handler, $col, $self-&gt;$co=
l, %opt );
<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; }<br>&lt;<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; foreach my $col ( sort keys %has_a ) {<br>&lt;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; $self-&gt;_emit_sax_value( $handler, $col, $self-&gt;$col, %o=
pt,<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wrapper =3D&gt; $c=
ol );
<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; }<br>&lt;<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; foreach my $col ( sort @{ $self-&gt;_has_many_methods =
|| [] } ) {<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $self-&gt;_emit_sax_value( $handle=
r, $col, $_, %opt )<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fo=
reach $self-&gt;$col;
<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; }<br>---<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fore=
ach my $col ( sort @plain ) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $self-&gt;_emit_sax_value( $handler, $co=
l, $self-&gt;$col, %opt );<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f=
oreach my $col ( sort keys %has_a ) {
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; $self-&gt;_emit_sax_value( $handler, $col, $self-&gt;$col, %opt,<br>&=
gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; wrapper =3D&gt; $col );<br>&gt;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; foreach my $col ( sort @{ $self-&gt;_has_many_methods =
|| [] } ) {
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; $self-&gt;_emit_sax_value( $handler, $col, $_, %opt )<br>&gt;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; foreach $self-&gt;$col;<br><br>-- <br>Eduardo Grosclaude<br>U=
niversidad Nacional del Comahue<br>Neuquen, Argentina

------=_Part_5717_25872284.1138822098579--


--===============0402174914==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

--===============0402174914==--

[CDBI] Adding behavior to Class::DBI::ToSax
Eduardo Grosclaude 19:28 on 01 Feb 2006

Generated at 17:59 on 03 Feb 2006 by mariachi v0.52