[Bps-public-commit] Net-Trac branch, master, updated. 980f3884b67877ddc00a0762e05e700c9d60561d

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed May 27 04:32:11 EDT 2009


The branch, master has been updated
       via  980f3884b67877ddc00a0762e05e700c9d60561d (commit)
       via  c3d23c54c3923f7fb5469aec903e447445aaf2d2 (commit)
       via  7e524cbcfc74bd25ebf30296eab17b035350fde2 (commit)
       via  4c6998c72014f31bb8f20568c1606a703cba0535 (commit)
       via  18918378a0814107b4fd0a6e9f49ed435dddc5b6 (commit)
      from  77d98e9b9155fc210b8c3102bcf6571c821c21e0 (commit)

Summary of changes:
 lib/Net/Trac/TicketAttachment.pm   |   65 ++++++++++++++++++++++++++++++++----
 lib/Net/Trac/TicketHistoryEntry.pm |   24 +++++++++++++-
 2 files changed, 81 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 18918378a0814107b4fd0a6e9f49ed435dddc5b6
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 15:52:21 2009 +0800

    update attachment parse part to satisify individual attachment page need

diff --git a/lib/Net/Trac/TicketAttachment.pm b/lib/Net/Trac/TicketAttachment.pm
index 018303f..49aae41 100644
--- a/lib/Net/Trac/TicketAttachment.pm
+++ b/lib/Net/Trac/TicketAttachment.pm
@@ -58,6 +58,7 @@ has url         => ( isa => 'Str',      is => 'rw' );
 has author      => ( isa => 'Str',      is => 'rw' );
 has size        => ( isa => 'Int',      is => 'rw' );
 
+
 =head1 PRIVATE METHODS
 
 =head2 _parse_html_chunk STRING
@@ -79,17 +80,42 @@ sub _parse_html_chunk {
 #                  Test description
 #                </dd>
 
+# for individual attachment page, the html is like:
+#
+#    <div id="content" class="attachment">
+#        <h1><a href="/xx/ticket/2">Ticket #2</a>: test.2.txt</h1>
+#        <table id="info" summary="Description">
+#          <tbody>
+#            <tr>
+#              <th scope="col">
+#                File test.2.txt, <span title="5 bytes">5 bytes</span>
+#                (added by sunnavy,  <a class="timeline" href="/xx/timeline?from=2009-05-27T14%3A31%3A02Z%2B0800&precision=second" title="2009-05-27T14:31:02Z+0800 in Timeline">13 seconds</a> ago)
+#              </th>
+#            </tr>
+#            <tr>
+#              <td class="message searchable">
+#                <p>
+#blalba
+#</p>
+#
+#              </td>
+#            </tr>
+#          </tbody>
+#        </table>
+#    </div>
+    
+
     $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->size($1)   if $html =~ qr{<span title="(\d+) bytes">};
-    $self->author($1) if $html =~ qr{added by <em>(.+?)</em>};
+    $self->author($1) if $html =~ qr{added by (?:<em>)?\s*(\w+)};
     if ( $html =~ qr{<a (?:.+?) title="(.+?) in Timeline">} ) {
         my $scalar_date = $1;
-       $self->date( Net::Trac::Ticket->timestamp_to_datetime($scalar_date));
-    }       
-    $self->description($1) if $html =~ qr{<dd>\s*(\S.*?)\s*</dd>\s*$};
+        $self->date( Net::Trac::Ticket->timestamp_to_datetime($scalar_date) );
+    }
+    $self->description($1) if $html =~ qr{(?:<dd>|<p>)\s*(.*?)\s*(?:</dd>|</p>)}s;
 
     return 1;
 }

commit 4c6998c72014f31bb8f20568c1606a703cba0535
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 15:56:44 2009 +0800

    added content and content_type attrs for Attachment

diff --git a/lib/Net/Trac/TicketAttachment.pm b/lib/Net/Trac/TicketAttachment.pm
index 49aae41..4f1fded 100644
--- a/lib/Net/Trac/TicketAttachment.pm
+++ b/lib/Net/Trac/TicketAttachment.pm
@@ -57,6 +57,19 @@ has description => ( isa => 'Str',      is => 'rw' );
 has url         => ( isa => 'Str',      is => 'rw' );
 has author      => ( isa => 'Str',      is => 'rw' );
 has size        => ( isa => 'Int',      is => 'rw' );
+has content => (
+    isa     => 'Str',
+    is      => 'rw',
+    lazy    => 1,
+    default => sub { $_[0]->_load },
+);
+
+has content_type => (
+    isa     => 'Str',
+    is      => 'rw',
+    lazy    => 1,
+    default => sub { $_[0]->_load },
+);
 
 
 =head1 PRIVATE METHODS
@@ -120,9 +133,16 @@ sub _parse_html_chunk {
     return 1;
 }
 
-sub content {
+sub _load {
     my $self = shift;
-    return $self->connection->_fetch( $self->url );
+    my $content = $self->connection->_fetch( $self->url );
+    my $content_type;
+    my $type_header = $self->connection->mech->response->header('Content-Type');
+    if ( $type_header =~ /(\S+?);/ ) {
+        $content_type = $1;
+    }
+    $self->content( $content );
+    $self->content_type( $content_type );
 }
 
 =head1 LICENSE

commit 7e524cbcfc74bd25ebf30296eab17b035350fde2
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 15:58:17 2009 +0800

    pod update for Attachment

diff --git a/lib/Net/Trac/TicketAttachment.pm b/lib/Net/Trac/TicketAttachment.pm
index 4f1fded..64e8e76 100644
--- a/lib/Net/Trac/TicketAttachment.pm
+++ b/lib/Net/Trac/TicketAttachment.pm
@@ -35,7 +35,11 @@ Relative to the remote Trac instance URL as set in the L<Net::Trac::Connection>.
 
 =head2 content
 
-Fetches and returns the content from the URL.
+returns the content of the attachment
+
+=head2 content_type
+
+returns the content_type of the attachment
 
 =head2 size
 

commit c3d23c54c3923f7fb5469aec903e447445aaf2d2
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 15:59:06 2009 +0800

    added attachment attr and parse it too for TicketHistoryEntry

diff --git a/lib/Net/Trac/TicketHistoryEntry.pm b/lib/Net/Trac/TicketHistoryEntry.pm
index 61ecca1..ba0817b 100644
--- a/lib/Net/Trac/TicketHistoryEntry.pm
+++ b/lib/Net/Trac/TicketHistoryEntry.pm
@@ -37,6 +37,10 @@ Returns a L<DateTime> object.
 Returns a hashref (property names as the keys) of
 L<Net::Trac::TicketPropChange>s associated with this history entry.
 
+=head2 attachment
+
+if there's attachment, return it, else, return undef
+
 =head2 ticket
 
 A weak reference to the ticket object for this ticket history entry
@@ -59,6 +63,7 @@ has author   => ( isa => 'Str',      is => 'rw' );
 has date     => ( isa => 'DateTime', is => 'rw' );
 has category => ( isa => 'Str',      is => 'rw' );
 has content  => ( isa => 'Str',      is => 'rw' );
+has attachment => ( isa => 'Net::Trac::TicketAttachment', is => 'rw' );
 has ticket  => ( isa => 'Net::Trac::Ticket',      is => 'rw', weak_ref => 1);
 
 =head1 METHODS
@@ -123,7 +128,24 @@ sub _parse_props {
     foreach my $line (@prop_lines) {
         my ($prop, $old, $new);
         if ($line =~ m{<strong>attachment</strong>}) {
-            # we can't handle trac's "attahcment changes" messages yet
+            my ($name) = $line =~ m!<em>(.*?)</em>!;
+            my $content = $self->connection->_fetch(
+                "/attachment/ticket/" . $self->ticket->id . "/$name" )
+              or next;
+
+            if ( $content =~
+                m{<div id="content" class="attachment">(.+?)</div>}is )
+            {
+                my $frag = $1;
+                my $att  = Net::Trac::TicketAttachment->new(
+                    connection => $self->connection,
+                    ticket     => $self->ticket->id,
+                    filename   => $name,
+                );
+                $att->_parse_html_chunk($frag);
+                $self->attachment( $att );
+            }
+
             next;
         }
         if ($line =~ m{<strong>description</strong>}) {

commit 980f3884b67877ddc00a0762e05e700c9d60561d
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 16:30:59 2009 +0800

    let _load return content and content_type so default values can use them

diff --git a/lib/Net/Trac/TicketAttachment.pm b/lib/Net/Trac/TicketAttachment.pm
index 64e8e76..5eb500a 100644
--- a/lib/Net/Trac/TicketAttachment.pm
+++ b/lib/Net/Trac/TicketAttachment.pm
@@ -65,14 +65,14 @@ has content => (
     isa     => 'Str',
     is      => 'rw',
     lazy    => 1,
-    default => sub { $_[0]->_load },
+    default => sub { ($_[0]->_load)[0] },
 );
 
 has content_type => (
     isa     => 'Str',
     is      => 'rw',
     lazy    => 1,
-    default => sub { $_[0]->_load },
+    default => sub { ($_[0]->_load)[1] },
 );
 
 
@@ -147,6 +147,7 @@ sub _load {
     }
     $self->content( $content );
     $self->content_type( $content_type );
+    return $content, $content_type;
 }
 
 =head1 LICENSE

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list