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

Eduardo Grosclaude eduardo.grosclaude at gmail.com
Wed Feb 1 19:28:18 GMT 2006


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 returns
a reference to a list with desired columns and order. Should keep former
ToSax behavior if not defined.
Thank you in advance.

[oso at osobox xml]$ diff ToSax.pm ToSax.pm.orig
86,112c86,97
<         if( $self->can( 'to_sax_columns' ) ) {
<                 my %has_many = map { $_ => 1 } @{ $self->_has_many_methods
|| [] };
<                 foreach my $col ( @{ $self->to_sax_columns } ) {
<                         if( defined $has_a{ $col } ) {
<                             $self->_emit_sax_value( $handler, $col,
$self->$col, %opt,
<                                 wrapper => $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 => $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 => $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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20060201/b13b8223/attachment.htm


More information about the ClassDBI mailing list