+++ /dev/null
-package CatalystX::HelpText::File;
-use Moose;
-use MooseX::Types::Moose qw/Str/;
-use Moose::Autobox;
-use Carp qw/confess/;
-use namespace::autoclean;
-
-has help_files_path => (
- is => 'ro',
- isa => Str,
- default => '/support/help/',
-);
-
-has help_files_ext => (
- is => 'ro',
- isa => Str,
- default => '.html',
-);
-
-sub get_help_text_for {
- my ($self, $c, $help_key) = @_;
- confess('No $c provided') unless $c;
- confess('No $help_key provided') unless $help_key;
-
- my $file_path = $c->path_to('root', $self->help_files_path.$help_key.$self->help_files_ext);
- my $string = '';
- if ( -e $file_path ) {
- local $/=undef;
- open FILE, $file_path or confess "Couldn't open file: $!";
- $string = <FILE>;
- close FILE;
- }
-
- return $string;
-}
-
-1;
-
--- /dev/null
+package CatalystX::HelpText::Model;
+use Moose;
+use MooseX::Types::Moose qw/Str Undef/;
+use MooseX::Types::Path::Class qw/ Dir /;
+use Moose::Autobox;
+use Carp qw/ croak confess/;
+use namespace::autoclean;
+
+extends 'Catalyst::Model';
+
+has help_files_path => (
+ is => 'ro',
+ isa => Dir,
+ coerce => 1,
+ required => 1,
+ handles => {
+ _get_file => 'file',
+ }
+);
+
+has help_files_ext => (
+ is => 'ro',
+ isa => Str|Undef,
+ default => 'html',
+);
+
+sub get_help_text_for {
+ my ($self, $help_key) = @_;
+ confess('No $help_key provided') unless $help_key;
+
+ my $fn = $help_key;
+ $fn .= "." . $self->help_files_ext if defined($self->help_files_ext);
+
+ my $file = $self->_get_file($fn);
+
+ return $file->slurp if ( -e $file );
+
+ croak "Cannot find help text '$help_key' in $file";
+}
+
+1;
+
extends 'Catalyst';
+__PACKAGE__->config('Model::Help' => { help_files_path => __PACKAGE__->path_to(qw/ root helptext /) });
__PACKAGE__->setup;
1;
--- /dev/null
+package TestApp::Model::Help;
+use Moose;
+use namespace::autoclean;
+
+extends 'CatalystX::HelpText::Model';
+
+1;
+
--- /dev/null
+blargh
\ No newline at end of file
use Test::WWW::Mechanize::Catalyst 'TestApp';
my $mech = Test::WWW::Mechanize::Catalyst->new;
$mech->get_ok('http://localhost/', 'get main page');
-$mech->content_like(qr/it works/i, 'see if it has our text');
+$mech->content_like(qr/fnarblarghfnee/i, 'see if it has our text');
done_testing;