Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Blosxom::Header to examples/

  • Loading branch information...
commit 33b970f975c125d0cdd7488c04f009daa173c164 1 parent 21d7f1a
Ryo Anazawa authored
Showing with 60 additions and 0 deletions.
  1. +23 −0 examples/lib/Blosxom/Header.pm
  2. +37 −0 examples/t/blosxom_header.t
23 examples/lib/Blosxom/Header.pm
View
@@ -0,0 +1,23 @@
+package Blosxom::Header;
+use strict;
+use warnings;
+use parent 'CGI::Header';
+use Carp qw/croak/;
+
+our $INSTANCE;
+
+sub new {
+ my $class = shift;
+ croak "Private method 'new' called for $class";
+}
+
+sub instance {
+ my $class = shift;
+ $INSTANCE ||= $class->SUPER::new( header => $blosxom::header );
+}
+
+sub has_instance {
+ $INSTANCE;
+}
+
+1;
37 examples/t/blosxom_header.t
View
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::Output;
+use Test::More tests => 2;
+
+BEGIN {
+ use_ok 'Blosxom::Header';
+}
+
+sub run_blosxom {
+ package blosxom;
+ require CGI;
+
+ our $static_entries = 0;
+ our $header = { -type => 'text/html' };
+ our $output = 'hello, world';
+
+ my $plugin = 'my_plugin';
+ $plugin->start && $plugin->last;
+
+ print CGI::header($header) . $output;
+}
+
+package my_plugin;
+
+sub start {
+ !$blosxom::static_entries;
+}
+
+sub last {
+ my $header = Blosxom::Header->instance;
+ $header->set( 'Content-Length' => length $blosxom::output );
+}
+
+package main;
+
+stdout_like \&run_blosxom, qr{Content-length: 12};
Please sign in to comment.
Something went wrong with that request. Please try again.