#!/usr/bin/perl
package Test::TAP::HTMLMatrix;
use fields qw/model extra petal has_inline_css/;
use strict;
use warnings;
use Test::TAP::Model::Visual;
use Petal;
use Carp qw/croak/;
use File::Spec;
use URI::file;
use overload '""' => "html";
our $VERSION = "0.04";
sub new {
my $pkg = shift;
my $model = shift || croak "must supply a model to graph";
my __PACKAGE__ $self = $pkg->fields::new;
my $ext = shift;
my $petal = shift || Petal->new(
file => File::Spec->abs2rel($self->template_file), # damn petal requires rel path
input => "XHTML",
output => "XHTML",
encode_charset => "utf8",
decode_charset => "utf8",
);
$self->model($model);
$self->extra($ext);
$self->petal($petal);
$self;
}
sub title { "TAP Matrix - " . gmtime() . " GMT" }
sub tests {
my $self = shift;
[ sort { $a->name cmp $b->name } $self->model->test_files ];
}
sub model {
my __PACKAGE__ $self = shift;
$self->{model} = shift if @_;
$self->{model};
}
sub extra {
my __PACKAGE__ $self = shift;
$self->{extra} = shift if @_;
$self->{extra};
}
sub petal {
my __PACKAGE__ $self = shift;
$self->{petal} = shift if @_;
$self->{petal};
}
sub html {
my __PACKAGE__ $self = shift;
$self->{petal}->process(page => $self);
}
sub _find_in_INC {
my $self = shift;
my $file = shift;
foreach my $str (grep { not ref } @INC){
my $target = File::Spec->catfile($str, $file);
return $target if -e $target;
}
die "couldn't find $file in \@INC";
}
sub _find_in_my_INC {
my $self = shift;
$self->_find_in_INC(File::Spec->catfile(split("::", __PACKAGE__), shift));
}
sub template_file {
my $self = shift;
$self->_find_in_my_INC("template.html");
}
sub css_file {
my $self = shift;
$self->_find_in_my_INC("htmlmatrix.css");
}
sub css_uri {
my $self = shift;
URI::file->new($self->css_file);
}
sub has_inline_css {
my $self = shift;
$self->{has_inline_css} = shift if @_;
$self->{has_inline_css};
}
sub _slurp_css {
my $self = shift;
local $/;
open my $fh, $self->css_file or die "open: " . $self->css_file. ": $!";
<$fh>;
}
sub inline_css {
my $self = shift;
"\n/\n";
}
__PACKAGE__
__END__
=pod
=head1 NAME
Test::TAP::HTMLMatrix - Creates colorful matrix of L
friendly test run results using L.
=head1 SYNOPSIS
use Test::TAP::HTMLMatrix;
use Test::TAP::Model::Visual;
my $model = Test::TAP::Model::Visual->new(...);
my $v = Test::TAP::HTMLMatrix->new($model);
print $v->html;
=head1 DESCRIPTION
This module is a wrapper for a template and some visualization classes, that
knows to take a L object, which encapsulates test results,
and produce a pretty html file.
=head1 METHODS
=over 4
=item new ($model, $?extra, $?petal)
$model is the L object to extract results from, and the
optional $?extra is a string to put in at the top.
$petal is an optional templater object. If you are not happy with the default
template, you can use this. Read the source to see how it's processed.
=item html
Returns an HTML string.
This is also the method implementing stringification.
=item model
=item extra
=item petal
Just settergetters. You can override these for added fun.
=item title
A reasonable title for the page:
"TAP Matrix - "
=item tests
A sorted array ref, resulting from $self->model->test_files;
=item template_file
=item css_file
These return the full path to the L template and the CSS stylesheet it
uses.
Note that these are taken from @INC. If you put F under
C< catfile(qw/Test TAP HTMLMatrix/) > somewhere in your @INC, it should find it
like you'd expect.
=item css_uri
This is a L object based on C. Nothing fancy.
You probably want to override this to something more specific to your env.
=item has_inline_css ?$new_value
This accessor controls whether inline CSS will be generated instead of C<<
>> style stylesheet refs.
=item inline_css
Returns the contents of C fudged slightly to work inside C<<