aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Check/Output/Mail
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Youri/Check/Output/Mail')
-rw-r--r--lib/Youri/Check/Output/Mail/Format.pm66
-rw-r--r--lib/Youri/Check/Output/Mail/Format/HTML.pm158
-rw-r--r--lib/Youri/Check/Output/Mail/Format/Text.pm83
3 files changed, 307 insertions, 0 deletions
diff --git a/lib/Youri/Check/Output/Mail/Format.pm b/lib/Youri/Check/Output/Mail/Format.pm
new file mode 100644
index 0000000..dee269e
--- /dev/null
+++ b/lib/Youri/Check/Output/Mail/Format.pm
@@ -0,0 +1,66 @@
+# $Id: Base.pm 579 2006-01-09 21:17:54Z guillomovitch $
+package Youri::Check::Output::Mail::Format;
+
+=head1 NAME
+
+Youri::Check::Output::Mail::Format - Abstract mail format support
+
+=head1 DESCRIPTION
+
+This abstract class defines the format support interface for
+L<Youri::Check::Output::Mail>.
+
+=cut
+
+use warnings;
+use strict;
+use Carp;
+
+sub new {
+ my $class = shift;
+ croak "Abstract class" if $class eq __PACKAGE__;
+
+ my %options = (
+ id => '',
+ test => 0,
+ verbose => 0,
+ @_
+ );
+
+ my $self = bless {
+ _id => $options{id},
+ _test => $options{test},
+ _verbose => $options{verbose},
+ }, $class;
+
+ $self->_init(%options);
+
+ return $self;
+}
+
+sub _init {
+ # do nothing
+}
+
+=head2 get_id()
+
+Returns format handler identity.
+
+=cut
+
+sub get_id {
+ my ($self) = @_;
+ croak "Not a class method" unless ref $self;
+
+ return $self->{_id};
+}
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2002-2006, YOURI project
+
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/lib/Youri/Check/Output/Mail/Format/HTML.pm b/lib/Youri/Check/Output/Mail/Format/HTML.pm
new file mode 100644
index 0000000..8ed4b28
--- /dev/null
+++ b/lib/Youri/Check/Output/Mail/Format/HTML.pm
@@ -0,0 +1,158 @@
+# $Id: Mail.pm 580 2006-01-11 22:59:36Z guillomovitch $
+package Youri::Check::Output::Mail::Format::HTML;
+
+=head1 NAME
+
+Youri::Check::Output::Mail::Format::HTML - Mail HTML format support
+
+=head1 DESCRIPTION
+
+This format plugin for L<Youri::Check::Output::Mail> provides HTML format
+support.
+
+=cut
+
+use warnings;
+use strict;
+use Carp;
+use CGI;
+use base 'Youri::Check::Output::Mail::Format';
+
+sub type {
+ return 'text/html';
+}
+
+sub _init {
+ my $self = shift;
+ my %options = (
+ style => <<EOF, # css style
+h1 {
+ text-align:center;
+}
+table {
+ border-style:solid;
+ border-width:1px;
+ border-color:black;
+ width:100%;
+}
+tr.odd {
+ background-color:white;
+}
+tr.even {
+ background-color:silver;
+}
+p.footer {
+ font-size:smaller;
+ text-align:center;
+}
+EOF
+ @_
+ );
+
+ $self->{_style} = $options{style};
+ $self->{_cgi} = CGI->new();
+}
+
+sub get_report {
+ my ($self, $time, $title, $iterator, $type, $columns, $links, $maintainer) = @_;
+
+ my $body;
+ my $lead_columns = [
+ $maintainer ?
+ qw/package media/ :
+ qw/package media maintainer/
+ ];
+ my $line;
+ my @results;
+ $body .= $self->{_cgi}->start_table();
+ $body .= $self->{_cgi}->Tr([
+ $self->{_cgi}->th([
+ @$lead_columns,
+ @$columns
+ ])
+ ]);
+ while (my $result = $iterator->get_result()) {
+ if (@results && $result->{package} ne $results[0]->{package}) {
+ $body .= $self->_get_formated_results(
+ $lead_columns,
+ $columns,
+ $links,
+ $line++ % 2 ? 'odd' : 'even',
+ \@results
+ );
+ @results = ();
+ }
+ push(@results, $result);
+ }
+ $body .= $self->_get_formated_results(
+ $lead_columns,
+ $columns,
+ $links,
+ $line++ % 2 ? 'odd' : 'even',
+ \@results
+ );
+ $body .= $self->{_cgi}->end_table();
+
+ my $content;
+ $content .= $self->{_cgi}->start_html(
+ -title => $title,
+ -style => { code => $self->{_style} }
+ );
+ $content .= $self->{_cgi}->h1($title);
+ $content .= $body;
+ $content .= $self->{_cgi}->hr();
+ $content .= $self->{_cgi}->p(
+ { class => 'footer' },
+ "Page generated $time"
+ );
+ $content .= $self->{_cgi}->end_html();
+
+ return \$content;
+}
+
+sub _get_formated_results {
+ my ($self, $lead_columns, $columns, $links, $class, $results) = @_;
+
+ my $content;
+ $content .= $self->{_cgi}->end_Tr();
+ for my $i (0 .. $#$results) {
+ $content .= $self->{_cgi}->start_Tr(
+ { class => $class }
+ );
+ if ($i == 0) {
+ # first line contains spanned cells
+ $content .= $self->{_cgi}->td(
+ { rowspan => scalar @$results },
+ [
+ map { $results->[$i]->{$_} }
+ @$lead_columns
+ ]
+ );
+ }
+ $content .= $self->{_cgi}->td(
+ [
+ map {
+ $links->{$_} && $results->[$i]->{$links->{$_}} ?
+ $self->{_cgi}->a(
+ { href => $results->[$i]->{$links->{$_}} },
+ $self->{_cgi}->escapeHTML($results->[$i]->{$_})
+ ) :
+ $self->{_cgi}->escapeHTML($results->[$i]->{$_})
+ } @$columns
+ ]
+ );
+ $content .= $self->{_cgi}->end_Tr();
+ }
+
+ return $content;
+}
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2002-2006, YOURI project
+
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/lib/Youri/Check/Output/Mail/Format/Text.pm b/lib/Youri/Check/Output/Mail/Format/Text.pm
new file mode 100644
index 0000000..f08e840
--- /dev/null
+++ b/lib/Youri/Check/Output/Mail/Format/Text.pm
@@ -0,0 +1,83 @@
+# $Id: Mail.pm 580 2006-01-11 22:59:36Z guillomovitch $
+package Youri::Check::Output::Mail::Format::Text;
+
+=head1 NAME
+
+Youri::Check::Output::Mail::Format::Text - Mail text format support
+
+=head1 DESCRIPTION
+
+This format plugin for L<Youri::Check::Output::Mail> provides text format
+support.
+
+=cut
+
+use warnings;
+use strict;
+use Carp;
+use base 'Youri::Check::Output::Mail::Format';
+
+sub type {
+ return 'text/plain';
+}
+
+sub get_report {
+ my ($self, $time, $title, $iterator, $type, $columns, $links, $maintainer) = @_;
+
+ my $content;
+ my $lead_columns = [
+ $maintainer ?
+ qw/package media/ :
+ qw/package media maintainer/
+ ];
+ my @results;
+ $content .= join("\t", @$lead_columns, @$columns) . "\n";
+ while (my $result = $iterator->get_result()) {
+ if (@results && $result->{package} ne $results[0]->{package}) {
+ $content .= $self->_get_formated_results(
+ $lead_columns,
+ $columns,
+ \@results
+ );
+ @results = ();
+ }
+ push(@results, $result);
+ }
+
+ $content .= $self->_get_formated_results(
+ $lead_columns,
+ $columns,
+ \@results
+ );
+
+ return \$content;
+}
+
+sub _get_formated_results {
+ my ($self, $lead_columns, $columns, $results) = @_;
+
+ my $content;
+ $content .= join(
+ "\t",
+ (map { $results->[0]->{$_} || '' } @$lead_columns),
+ (map { $results->[0]->{$_} || '' } @$columns)
+ ) . "\n";
+ for my $i (1 .. $#$results) {
+ $content .= join(
+ "\t",
+ (map { '' } @$lead_columns),
+ (map { $results->[$i]->{$_} || '' } @$columns)
+ ) . "\n";
+ }
+ return $content;
+}
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2002-2006, YOURI project
+
+This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;