[Bps-public-commit] r17469 - in Net-Trac/trunk: .

trs at bestpractical.com trs at bestpractical.com
Tue Dec 30 23:12:12 EST 2008


Author: trs
Date: Tue Dec 30 23:12:12 2008
New Revision: 17469

Modified:
   Net-Trac/trunk/   (props changed)
   Net-Trac/trunk/lib/Net/Trac/Ticket.pm
   Net-Trac/trunk/lib/Net/Trac/TicketAttachment.pm

Log:
 r43326 at zot:  tom | 2008-12-30 23:09:32 -0500
 Fix the way we parse the attachment dl so that we don't skip attachments without descriptions


Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm	Tue Dec 30 23:12:12 2008
@@ -238,10 +238,11 @@
     my $content = $self->connection->_fetch("/attachment/ticket/".$self->id."/");
     
     if ( $content =~ m{<dl class="attachments">(.+?)</dl>}is ) {
-        my $html = $1;
-        my @attachments;
+        my $html = $1 . '<dt>'; # adding a <dt> here is a hack that lets us
+                                # reliably parse this with one regex
 
-        while ( $html =~ m{<dt>(.+?)</dd>}gis ) {
+        my @attachments;
+        while ( $html =~ m{<dt>(.+?)(?=<dt>)}gis ) {
             my $fragment = $1;
             my $attachment = Net::Trac::TicketAttachment->new({
                 connection => $self->connection,

Modified: Net-Trac/trunk/lib/Net/Trac/TicketAttachment.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketAttachment.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketAttachment.pm	Tue Dec 30 23:12:12 2008
@@ -34,27 +34,20 @@
 #    </dt>
 #                <dd>
 #                  Test description
+#                </dd>
     
-    $self->_fill_property( $html, 'filename', qr{<a (?:.+?) title="View attachment">(.+?)</a>} );
+    $self->filename($1) if $html =~ qr{<a (?:.+?) title="View attachment">(.+?)</a>};
     $self->url( "/raw-attachment/ticket/" . $self->ticket . "/" . $self->filename )
         if defined $self->filename;
 
-    $self->_fill_property( $html, size          => qr{<span title="(\d+) bytes">} );
-    $self->_fill_property( $html, author        => qr{added by <em>(.+?)</em>} );
-    $self->_fill_property( $html, date          => qr{<a (?:.+?) title="(.+?) in Timeline">} );
-    $self->_fill_property( $html, description   => qr{<dd>\s*(\S.*?)\s*$} );
+    $self->size($1)         if $html =~ qr{<span title="(\d+) bytes">};
+    $self->author($1)       if $html =~ qr{added by <em>(.+?)</em>};
+    $self->date($1)         if $html =~ qr{<a (?:.+?) title="(.+?) in Timeline">};
+    $self->description($1)  if $html =~ qr{<dd>\s*(\S.*?)\s*</dd>\s*$};
 
     return 1;
 }
 
-sub _fill_property {
-    my ($self, $html, $prop, $regex) = @_;
-    if ( $html =~ $regex ) {
-        $self->$prop( $1 );
-    }
-    else { warn "Unable to find attachment $prop!" }
-}
-
 sub content {
     my $self = shift;
     return $self->connection->_fetch( $self->url );



More information about the Bps-public-commit mailing list