initial code to get help from files
Cinxgler Mariaca Minda [Fri, 23 Sep 2011 14:33:42 +0000 (14:33 +0000)]
lib/CatalystX/HelpText.pm
lib/CatalystX/HelpText/File.pm [new file with mode: 0644]
lib/CatalystX/HelpText/Role/HelpText.pm [new file with mode: 0644]

index d308fae..182e9d3 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 
 =head1 NAME
 
-CatalystX::HelpText - 
+CatalystX::HelpText -
 
 =head1 DESCRIPTION
 
@@ -16,9 +16,13 @@ CatalystX::HelpText -
 
 =head1 AUTHOR
 
-=head1 COPYRIGHT & LICENSE
+Cinxgler Mariaca Minda,C<cinxgler at ci-info.com>
 
-Copyright 2009 the above author(s).
+=head1 COPYRIGHT
+
+Copyright state51.
+
+=head1 LICENSE
 
 This sofware is free software, and is licensed under the same terms as perl itself.
 
diff --git a/lib/CatalystX/HelpText/File.pm b/lib/CatalystX/HelpText/File.pm
new file mode 100644 (file)
index 0000000..ee2e851
--- /dev/null
@@ -0,0 +1,37 @@
+package CatalystX::HelpText::File;
+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 = '';
+    my $source = $self->source_help_url.$help_key;
+    if ( -e $file_path ) {
+        local $/=undef;
+        open FILE, $file_path or confess "Couldn't open file: $!";
+        $string = <FILE>;
+        close FILE;
+    }
+
+    return $string;
+}
+
+1;
diff --git a/lib/CatalystX/HelpText/Role/HelpText.pm b/lib/CatalystX/HelpText/Role/HelpText.pm
new file mode 100644 (file)
index 0000000..1ff495e
--- /dev/null
@@ -0,0 +1,16 @@
+package CatalystX::HelpText::Role::HelpText;
+use Moose::Role;
+use Try::Tiny;
+
+sub help_text {
+    my ($self, $c, $key) = @_;
+    try {
+        return $c->model('Help')->get_help_text_for($c, $key);
+    }
+    catch {
+        $c->log->warn("Error retrieving help_text: ".$_);
+        return '';
+    };
+}
+
+1;
\ No newline at end of file