my $bug = Emesinae::Bug->new( $dbh, ID => $bugid );
fourohfour() unless $bug;
-if ( $mode eq "mbox" ) {
- print header( -type => 'application/mbox', -charset => 'utf-8', );
-
- foreach my $m ( sort msgcmp $bug->messages ) {
- eval {
- my $fh;
-
- # Could forge a placeholder for messages which aren't present here.
-
- $fh = $m->headers;
- print for (<$fh>);
-
+my %handlers = (
+ mbox => {
+ Header => sub () { print header( -type => 'application/mbox', -charset => 'utf-8', ); },
+ Message => sub ($) {
+ my $m = shift;
+ eval {
+ my $fh;
+
+ # Could forge a placeholder for messages which aren't present here.
+
+ $fh = $m->headers;
+ print for (<$fh>);
+
+ print "\n";
+
+ $fh = $m->body;
+ print for (<$fh>);
+ };
+ # Ignore errors...
+ },
+ Footer => sub () { }
+ },
+ normal => {
+ Header => sub () {
+ print header( -charset => 'utf-8', );
+
+ print start_html(
+ -title => $c{TrackerName} . ": #$bugid - " . htmlsanit( $bug->{title} ),
+ -style => { 'src' => $c{StyleSheet} }
+ );
+
+ print h1( "#$bugid - " . htmlsanit( $bug->{title} ) );
print "\n";
- $fh = $m->body;
- print for (<$fh>);
- };
+ sub fmtdate ($) {
+ return htmlsanit( strftime( "%a %b %e %H:%M:%S %Y", gmtime(shift) ) );
+ }
+
+ my $creationdate = fmtdate( $bug->{creationdate} );
+ my $lastchangedate = fmtdate( $bug->{lastchangedate} );
+ print div(
+ { -class => "bugmetadata" },
+ p(
+ [
+ "Owner: " . htmlsanit( $bug->{owner} ),
+ "Date: " . htmlsanit($creationdate),
+ "Last Update: " . htmlsanit($lastchangedate),
+ "Severity: " . htmlsanit( $bug->{severity} ),
+ "Affects: " . htmlsanit( join( ", ", $bug->tags("affects") ) ),
+ "State: " . b( $bug->{open} ? "Open" : "Closed" )
+ ]
+ )
+ );
+
+ print p( { -class => "bugcontrol" },
+ "[ " . buglink( $bug, "Retrieve as mbox", "/mbox" ) . " ]" )
+ . "\n";
+
+ print hr;
- # Ignore errors...
+ print "\n";
+ },
+ Message => sub ($) { format_html(shift, $bug); print hr . "\n" },
+ Footer => sub () { print end_html }
}
-
- exit(0);
-}
-
-print header( -charset => 'utf-8', );
-print start_html(
- -title => $c{TrackerName} . ": #$bugid - " . htmlsanit( $bug->{title} ),
- -style => { 'src' => $c{StyleSheet} }
);
-print h1( "#$bugid - " . htmlsanit( $bug->{title} ) );
-print "\n";
-
-sub fmtdate ($) {
- return htmlsanit( strftime( "%a %b %e %H:%M:%S %Y", gmtime(shift) ) );
-}
-
-my $creationdate = fmtdate( $bug->{creationdate} );
-my $lastchangedate = fmtdate( $bug->{lastchangedate} );
-print div(
- { -class => "bugmetadata" },
- p(
- [
- "Owner: " . htmlsanit( $bug->{owner} ),
- "Date: " . htmlsanit($creationdate),
- "Last Update: " . htmlsanit($lastchangedate),
- "Severity: " . htmlsanit( $bug->{severity} ),
- "Affects: " . htmlsanit( join( ", ", $bug->tags("affects") ) ),
- "State: " . b( $bug->{open} ? "Open" : "Closed" )
- ]
- )
-);
-
-print p( { -class => "bugcontrol" },
- "[ " . buglink( $bug, "Retrieve as mbox", "/mbox" ) . " ]" )
- . "\n";
-
-print hr;
-
-print "\n\n";
+die "Bad/unknown mode $mode" unless defined $handlers{$mode};
-print "\n";
+$handlers{$mode}{Header}();
sub msgcmp {
my $atime = $a->{present} ? $a->{date}->time : 0;
}
foreach my $m ( sort msgcmp $bug->messages ) {
- format_html($m, $bug);
- print hr . "\n";
+ $handlers{$mode}{Message}($m);
}
-print end_html;
+$handlers{$mode}{Footer}();