File Coverage

blib/lib/Plack/Middleware/GNUTerryPratchett.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Plack::Middleware::GNUTerryPratchett;
2              
3             # ABSTRACT: Adds automatically an X-Clacks-Overhead header.
4              
5 1     1   492 use strict;
  1         1  
  1         30  
6 1     1   4 use warnings;
  1         1  
  1         27  
7 1     1   10 use Plack::Util;
  1         0  
  1         51  
8              
9             our $VERSION = '0.01';
10              
11 1     1   6 use parent qw/Plack::Middleware/;
  1         2  
  1         9  
12              
13             sub call {
14 1     1 1 16551 my $self = shift;
15 1         10 my $res = $self->app->(@_);
16              
17             $self->response_cb(
18             $res,
19             sub {
20 1     1   18 my $res = shift;
21 1         2 my $headers = $res->[1];
22 1 50       4 return if ( Plack::Util::header_exists( $headers, 'X-Clacks-Overhead' ) );
23 1         24 Plack::Util::header_set( $headers, 'X-Clacks-Overhead', 'GNU Terry Pratchett' );
24 1         22 return;
25             }
26 1         83 );
27             }
28              
29             1;
30              
31             =pod
32              
33             =head1 NAME
34              
35             Plack::Middleware::GNUTerryPratchett - Adds automatically an X-Clacks-Overhead header.
36              
37             =head1 VERSION
38              
39             version 0.01
40              
41             =head1 SYNOPSIS
42              
43             use Plack::Builder;
44              
45             my $app = builder {
46             enable "Plack::Middleware::GNUTerryPratchett";
47             sub {[ '200', ['Content-Type' => 'text/html'], ['hello world']] }
48             };
49              
50             =head1 DESCRIPTION
51              
52             Plack::Middleware::GNUTerryPratchett adds automatically an X-Clacks-Overhead header.
53              
54             In Terry Pratchett's Discworld series, the clacks are a series of semaphore towers loosely based on the concept of the telegraph. Invented by an artificer named Robert Dearheart, the towers could send messages "at the speed of light" using standardized codes. Three of these codes are of particular import:
55              
56             B: send the message on
57              
58             B: do not log the message
59              
60             B: turn the message around at the end of the line and send it back again
61             When Dearheart died, his name was inserted into the overhead of the clacks with a "GNU" in front of it to memorialize him forever (or for at least as long as the clacks are standing.)
62              
63             For more information: L
64              
65             =head1 AUTHOR
66              
67             Tiago Peczenyj
68              
69             =cut