]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/CLI.pm
+ Use HTTP::Headers for input/output headers. Add appropriate unit tests.
[maypole.git] / lib / Maypole / CLI.pm
index 0fd3fa3fe9c57589ef608b2c9e804288864367c5..504d0b428a18596aa373a66d4643f7bbe207814b 100644 (file)
@@ -9,6 +9,13 @@ use warnings;
 my $package;
 our $buffer;
 
+# Command line action
+CHECK {
+    if ( ( caller(0) )[1] eq "-e" ) {
+        $package->handler() == OK and print $buffer;
+    }
+}
+
 sub import {
     $package = $_[1];
     $package->require;
@@ -17,7 +24,6 @@ sub import {
     unshift @{ $package . "::ISA" }, "Maypole::CLI";
 }
 
-sub get_request       { }
 sub get_template_root { $ENV{MAYPOLE_TEMPLATES} || "." }
 
 sub parse_location {
@@ -25,8 +31,8 @@ sub parse_location {
     my $url  = URI->new( shift @ARGV );
     my $root = URI->new( $self->config->uri_base )->path;
     $self->{path} = $url->path;
+    $self->{path} .= '/' if $self->{path} eq $root;
     $self->{path} =~ s/^$root//i if $root;
-    $self->rewrite_path;
     $self->parse_path;
     $self->parse_args($url);
 }
@@ -45,12 +51,6 @@ sub call_url {
     $package->handler() == OK and return $buffer;
 }
 
-# Do it!
-CHECK {
-    if ( ( caller(0) )[1] eq "-e" ) {
-        $package->handler() == OK and print $buffer;
-    }
-}
 
 1;
 
@@ -99,7 +99,7 @@ more easily.
 
 For instance, a test script could look like this:
 
-    use Test::More tests => 5;
+    use Test::More tests => 3;
     use Maypole::CLI qw(BeerDB);
     use Maypole::Constants;
     $ENV{MAYPOLE_TEMPLATES} = "t/templates";
@@ -107,11 +107,36 @@ For instance, a test script could look like this:
     # Hack because isa_ok only supports object isa not class isa
     isa_ok( (bless {},"BeerDB") , "Maypole");
 
-    @ARGV = ("http://localhost/beerdb/");
-    is(BeerDB->handler, OK, "OK");
-    like($Maypole::CLI::buffer, qr/frontpage/, "Got the front page");
+    like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/, "Got the front page");
+
+    like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list");
+
+=head1 METHODS 
+
+=over 
+
+=item call_url
+
+for use in scripts. takes an url as argument, and returns the buffer. 
+
+=back
+
+
+=head1 Implementation
+
+This class overrides a set of methods in the base Maypole class to provide it's 
+functionality. See L<Maypole> for these:
+
+=over
+
+=item get_template_root
+
+=item parse_args
+
+=item parse_location
+
+=item send_output
 
-    @ARGV = ("http://localhost/beerdb/beer/list");
-    is(BeerDB->handler, OK, "OK");
-    like($Maypole::CLI::buffer, qr/Organic Best/, "Found a beer in the list");
+=back
 
+=cut