| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | RDF::EARL - Generate W3C Evaluation and Report Language (EARL) test reports. | ||||||||||
| 4 | |||||||||||
| 5 | =head1 VERSION | ||||||||||
| 6 | |||||||||||
| 7 | This document describes RDF::EARL version 0.002. | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | my $earl = RDF::EARL->new('http://thing-being-tested/'); | ||||||||||
| 12 | $earl->pass('http://example.org/test1'); | ||||||||||
| 13 | $earl->pass('http://example.org/test2'); | ||||||||||
| 14 | $earl->fail('http://example.org/test3', 'failure explanation'); | ||||||||||
| 15 | my $model = $earl->model; | ||||||||||
| 16 | # $model is a Attean::API::Model containing the test results in EARL format | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | RDF::EARL allows generating test reports using the W3C | ||||||||||
| 21 | L<Evaluation and Report Language (EARL) 1.0 RDF vocabulary|http://www.w3.org/TR/EARL10-Schema/>. | ||||||||||
| 22 | |||||||||||
| 23 | Test reports are generated by defining a subject (the thing being tested), an | ||||||||||
| 24 | assertor (the thing doing the testing), and the result of a number of performed | ||||||||||
| 25 | tests. The result can be one of: passed, failed, can't tell, inapplicable, and untested | ||||||||||
| 26 | (see the methods below, or the EARL 1.0 documentation for more details). | ||||||||||
| 27 | |||||||||||
| 28 | Once the test results have been asserted, the EARL report data may be accessed | ||||||||||
| 29 | in an Attean::API::Model. This allows the testing system to augment the test data | ||||||||||
| 30 | with supplementary data such as links to or contact information for obtaining | ||||||||||
| 31 | more information about the subject, assertor, or testing setup. | ||||||||||
| 32 | |||||||||||
| 33 | Alternatively, the C<< as_string >> method will return the EARL report RDF data | ||||||||||
| 34 | as a string in the Turtle RDF format. | ||||||||||
| 35 | |||||||||||
| 36 | =head1 METHODS | ||||||||||
| 37 | |||||||||||
| 38 | =over 4 | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | package RDF::EARL; | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | 2 | ▶ | use feature qw(unicode_strings); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 2 | ▶ | use Attean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 2 | ▶ | use Encode qw(decode_utf8); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 2 | ▶ | use Attean::RDF qw(iri blank literal quad); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 2 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 53 | |||||||||||
| 54 | 2 | our ($VERSION); | |||||||||
| 55 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 2 | $VERSION = '0.002'; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 2 | my $rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; | |||||||||
| 60 | 2 | my $rdfs = 'http://www.w3.org/2000/01/rdf-schema#'; | |||||||||
| 61 | 2 | my $foaf = 'http://xmlns.com/foaf/0.1/'; | |||||||||
| 62 | 2 | my $dc_terms = 'http://purl.org/dc/terms/'; | |||||||||
| 63 | 2 | my $xsd = 'http://www.w3.org/2001/XMLSchema#'; | |||||||||
| 64 | 2 | my $DOAP = 'http://usefulinc.com/ns/doap#'; | |||||||||
| 65 | 2 | my $EARL = 'http://www.w3.org/ns/earl#'; | |||||||||
| 66 | |||||||||||
| 67 | =item C<< new ( $subj_iri ) >> | ||||||||||
| 68 | |||||||||||
| 69 | =item C<< new ( subject => $subj_iri, assertor => $assertor_iri ) >> | ||||||||||
| 70 | |||||||||||
| 71 | Creates a new EARL testing object for asserting results of testing the thing | ||||||||||
| 72 | (code, project, etc.) represented by C<< $subj_iri >> by the testing code | ||||||||||
| 73 | represented by C<< $assertor_iri >>. If the C<< assertor >> key-value pair is | ||||||||||
| 74 | omitted, a default value for the RDF::EARL module will be used by default. | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | coerce 'Attean::IRI', | ||||||||||
| 79 | from 'Str', | ||||||||||
| 80 | 8 | ▶ | via { iri($_) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 81 | |||||||||||
| 82 | has model => ( | ||||||||||
| 83 | is => 'ro', | ||||||||||
| 84 | isa => 'Attean::API::Model', | ||||||||||
| 85 | 6 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 6 | my $store = Attean->get_store('Memory')->new(); | |||||||||
| 87 | 6 | my $model = Attean::MutableQuadModel->new( store => $store ); | |||||||||
| 88 | }, | ||||||||||
| 89 | 2 | ); | |||||||||
| 90 | |||||||||||
| 91 | 2 | has subject => ( | |||||||||
| 92 | is => 'rw', | ||||||||||
| 93 | isa => 'Attean::IRI', | ||||||||||
| 94 | coerce => 1, | ||||||||||
| 95 | required => 1, | ||||||||||
| 96 | ); | ||||||||||
| 97 | |||||||||||
| 98 | has graph => ( | ||||||||||
| 99 | is => 'rw', | ||||||||||
| 100 | isa => 'Attean::IRI', | ||||||||||
| 101 | coerce => 1, | ||||||||||
| 102 | required => 1, | ||||||||||
| 103 | 6 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 104 | 6 | return iri('http://example.org/') | |||||||||
| 105 | }, | ||||||||||
| 106 | 2 | ); | |||||||||
| 107 | |||||||||||
| 108 | has assertor => ( | ||||||||||
| 109 | is => 'rw', | ||||||||||
| 110 | isa => 'Attean::IRI', | ||||||||||
| 111 | coerce => 1, | ||||||||||
| 112 | 3 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 113 | 3 | my $vers = $VERSION =~ s/[.]/-/gr; | |||||||||
| 114 | 3 | return iri("http://purl.org/NET/cpan-uri/dist/RDF-EARL/v_${vers}"); | |||||||||
| 115 | }, | ||||||||||
| 116 | 2 | ); | |||||||||
| 117 | |||||||||||
| 118 | 6 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 119 | 6 | my $orig = shift; | |||||||||
| 120 | 6 | my $class = shift; | |||||||||
| 121 | 6 | ▶ | if (scalar(@_) == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 1 | return $class->$orig( subject => shift ); | |||||||||
| 123 | } else { | ||||||||||
| 124 | 5 | return $class->$orig( @_ ); | |||||||||
| 125 | } | ||||||||||
| 126 | 2 | }; | |||||||||
| 127 | |||||||||||
| 128 | =item C<< assertor >> | ||||||||||
| 129 | |||||||||||
| 130 | Returns the Attean::IRI object representing the thing doing the | ||||||||||
| 131 | testing. This is either the IRI passed to the constructor as C<<assertor>> or | ||||||||||
| 132 | a RDF::EARL IRI like L<http://purl.org/NET/cpan-uri/dist/RDF-EARL/v_0-001>. | ||||||||||
| 133 | |||||||||||
| 134 | =cut | ||||||||||
| 135 | |||||||||||
| 136 | =item C<< subject >> | ||||||||||
| 137 | |||||||||||
| 138 | Returns the Attean::IRI object representing the thing being | ||||||||||
| 139 | tested. This is the IRI passed to the constructor as C<<subject>>. | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||
| 142 | |||||||||||
| 143 | =item C<< model >> | ||||||||||
| 144 | |||||||||||
| 145 | Returns the Attean::API::Model object containing the EARL result data. | ||||||||||
| 146 | |||||||||||
| 147 | =cut | ||||||||||
| 148 | |||||||||||
| 149 | 3 | ▶ | sub _assert { | ||||||||
|
Subroutine
_assert: called CC=4 SCAR=13.9
| |||||||||||
| 150 | 3 | my $self = shift; | |||||||||
| 151 | 3 | my $test = shift; | |||||||||
| 152 | 3 | my $result = shift; | |||||||||
| 153 | 3 | my @comment = @_; | |||||||||
| 154 | |||||||||||
| 155 | 3 | ▶ | unless (blessed($test)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | 3 | $test = iri($test); | |||||||||
| 157 | } | ||||||||||
| 158 | 3 | my $model = $self->model; | |||||||||
| 159 | 3 | my $GRAPH = $self->graph; | |||||||||
| 160 | 3 | my $a = blank(); | |||||||||
| 161 | 3 | my $r = blank(); | |||||||||
| 162 | 3 | $model->add_quad( quad($a, iri("${rdf}type"), iri("${EARL}Assertion"), $GRAPH) ); | |||||||||
| 163 | 3 | $model->add_quad( quad($a, iri("${EARL}assertedBy"), $self->assertor, $GRAPH) ); | |||||||||
| 164 | 3 | $model->add_quad( quad($a, iri("${EARL}subject"), $self->subject, $GRAPH) ); | |||||||||
| 165 | 3 | $model->add_quad( quad($a, iri("${EARL}test"), $test, $GRAPH) ); | |||||||||
| 166 | 3 | $model->add_quad( quad($a, iri("${EARL}result"), $r, $GRAPH) ); | |||||||||
| 167 | 3 | $model->add_quad( quad($r, iri("${rdf}type"), iri("${EARL}TestResult"), $GRAPH) ); | |||||||||
| 168 | 3 | $model->add_quad( quad($r, iri("${EARL}outcome"), $result, $GRAPH) ); | |||||||||
| 169 | 3 | foreach my $c (@comment) { | |||||||||
| 170 | 3 | ▶ | my $l = blessed($c) ? $c : literal($c); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 171 | 3 | $model->add_quad( quad($r, iri("${EARL}info"), $l, $GRAPH) ); | |||||||||
| 172 | } | ||||||||||
| 173 | 3 | return $a; | |||||||||
| 174 | } | ||||||||||
| 175 | |||||||||||
| 176 | =item C<< pass ( $test, @comments ) >> | ||||||||||
| 177 | |||||||||||
| 178 | Asserts that the test identifed by the C<< $test >> IRI was passed by the subject | ||||||||||
| 179 | system. If there are any C<< @comments >> specified, they are asserted as | ||||||||||
| 180 | earl:info statements on the respective earl:TestResult node in the result | ||||||||||
| 181 | model. | ||||||||||
| 182 | Returns the Attean::API::Term object corresponding to the just-made assertion. | ||||||||||
| 183 | |||||||||||
| 184 | =cut | ||||||||||
| 185 | |||||||||||
| 186 | 2 | ▶ | sub pass { | ||||||||
|
Subroutine
pass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 187 | 2 | my $self = shift; | |||||||||
| 188 | 2 | my $test = shift; | |||||||||
| 189 | 2 | return $self->_assert($test, iri("${EARL}passed"), @_); | |||||||||
| 190 | } | ||||||||||
| 191 | |||||||||||
| 192 | =item C<< fail ( $test, @comments ) >> | ||||||||||
| 193 | |||||||||||
| 194 | Asserts that the test identifed by the C<< $test >> IRI was failed by the subject | ||||||||||
| 195 | system. If there are any C<< @comments >> specified, they are asserted as | ||||||||||
| 196 | earl:info statements on the respective earl:TestResult node in the result | ||||||||||
| 197 | model. | ||||||||||
| 198 | Returns the Attean::API::Term object corresponding to the just-made assertion. | ||||||||||
| 199 | |||||||||||
| 200 | =cut | ||||||||||
| 201 | |||||||||||
| 202 | 1 | ▶ | sub fail { | ||||||||
|
Subroutine
fail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 203 | 1 | my $self = shift; | |||||||||
| 204 | 1 | my $test = shift; | |||||||||
| 205 | 1 | return $self->_assert($test, iri("${EARL}failed"), @_); | |||||||||
| 206 | } | ||||||||||
| 207 | |||||||||||
| 208 | =item C<< cantTell ( $test, @comments ) >> | ||||||||||
| 209 | |||||||||||
| 210 | Asserts that it is unclear if the subject passed or failed the test identifed | ||||||||||
| 211 | by the C<< $test >> IRI. If there are any C<< @comments >> specified, they are | ||||||||||
| 212 | asserted as earl:info statements on the respective earl:TestResult node in | ||||||||||
| 213 | the result model. | ||||||||||
| 214 | Returns the Attean::API::Term object corresponding to the just-made assertion. | ||||||||||
| 215 | |||||||||||
| 216 | =cut | ||||||||||
| 217 | |||||||||||
| 218 | 0 | ▶ | sub cantTell { | ||||||||
|
Subroutine
cantTell: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 219 | 0 | my $self = shift; | |||||||||
| 220 | 0 | my $test = shift; | |||||||||
| 221 | 0 | return $self->_assert($test, iri("${EARL}cantTell"), @_); | |||||||||
| 222 | } | ||||||||||
| 223 | |||||||||||
| 224 | =item C<< inapplicable ( $test, @comments ) >> | ||||||||||
| 225 | |||||||||||
| 226 | Asserts that the test identifed by the C<< $test >> IRI is not applicable to the | ||||||||||
| 227 | subject system. If there are any C<< @comments >> specified, they are asserted as | ||||||||||
| 228 | earl:info statements on the respective earl:TestResult node in the result | ||||||||||
| 229 | model. | ||||||||||
| 230 | Returns the Attean::API::Term object corresponding to the just-made assertion. | ||||||||||
| 231 | |||||||||||
| 232 | =cut | ||||||||||
| 233 | |||||||||||
| 234 | 0 | ▶ | sub inapplicable { | ||||||||
|
Subroutine
inapplicable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 235 | 0 | my $self = shift; | |||||||||
| 236 | 0 | my $test = shift; | |||||||||
| 237 | 0 | return $self->_assert($test, iri("${EARL}inapplicable"), @_); | |||||||||
| 238 | } | ||||||||||
| 239 | |||||||||||
| 240 | =item C<< untested ( $test, @comments ) >> | ||||||||||
| 241 | |||||||||||
| 242 | Asserts that the test identifed by the C<< $test >> IRI was not tested by the | ||||||||||
| 243 | subject system. If there are any C<< @comments >> specified, they are asserted as | ||||||||||
| 244 | earl:info statements on the respective earl:untested node in the result | ||||||||||
| 245 | model. | ||||||||||
| 246 | Returns the Attean::API::Term object corresponding to the just-made assertion. | ||||||||||
| 247 | |||||||||||
| 248 | =cut | ||||||||||
| 249 | |||||||||||
| 250 | 0 | ▶ | sub untested { | ||||||||
|
Subroutine
untested: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 251 | 0 | my $self = shift; | |||||||||
| 252 | 0 | my $test = shift; | |||||||||
| 253 | 0 | return $self->_assert($test, iri("${EARL}untested"), @_); | |||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | =item C<< as_string >> | ||||||||||
| 257 | |||||||||||
| 258 | Returns EARL report data as a string formatted as Turtle. | ||||||||||
| 259 | |||||||||||
| 260 | =cut | ||||||||||
| 261 | |||||||||||
| 262 | 0 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: not called CC=1 SCAR=4.0
Pod
documented
| |||||||||||
| 263 | 0 | my $self = shift; | |||||||||
| 264 | 0 | my $model = $self->model; | |||||||||
| 265 | 0 | my $mapper = Attean::TermMap->short_blank_map; | |||||||||
| 266 | 0 | my $bindings_mapper = $mapper->binding_mapper; | |||||||||
| 267 | 0 | ▶ | my $iter = $model->get_quads()->map(sub { Attean::Triple->new(($_->values)[0..2]) }, 'Attean::API::Triple'); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 268 | 0 | my $short_iter = $iter->map( $bindings_mapper ); | |||||||||
| 269 | 2 | ▶ | use URI::NamespaceMap; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 270 | 0 | my $map = URI::NamespaceMap->new( { earl => iri($EARL), rdf => iri($rdf) } ); | |||||||||
| 271 | 0 | my $ser = Attean->get_serializer('Turtle')->new; | |||||||||
| 272 | 0 | my $ttl = decode_utf8($ser->serialize_iter_to_bytes($iter)); | |||||||||
| 273 | 0 | return $ttl; | |||||||||
| 274 | } | ||||||||||
| 275 | |||||||||||
| 276 | 0 | ▶ | sub _debug { | ||||||||
|
Subroutine
_debug: not called CC=1 SCAR=6.9
| |||||||||||
| 277 | 0 | my $self = shift; | |||||||||
| 278 | 0 | warn $self->as_string . "\n"; | |||||||||
| 279 | } | ||||||||||
| 280 | |||||||||||
| 281 | 2 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 282 | |||||||||||
| 283 | 2 | 1; | |||||||||
| 284 | |||||||||||
| 285 | |||||||||||
| 286 | =back | ||||||||||
| 287 | |||||||||||
| 288 | =head1 SEE ALSO | ||||||||||
| 289 | |||||||||||
| 290 | L<http://www.w3.org/TR/EARL10-Schema/> | ||||||||||
| 291 | |||||||||||
| 292 | =head1 AUTHOR | ||||||||||
| 293 | |||||||||||
| 294 | Gregory Todd Williams <gwilliams@cpan.org> | ||||||||||
| 295 | |||||||||||
| 296 | =head1 LICENSE | ||||||||||
| 297 | |||||||||||
| 298 | Copyright (c) 2012 Gregory Todd Williams. This | ||||||||||
| 299 | program is free software; you can redistribute it and/or modify it under | ||||||||||
| 300 | the same terms as Perl itself. | ||||||||||
| 301 | |||||||||||
| 302 | =cut | ||||||||||