summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-08-12 14:26:02 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-08-12 14:26:02 (EDT)
commit7863497dde842b1ab30a7a74c76f150a8424d74b (patch)
treedb79623e3cae0d0ec0557d17ea6cf8126d0917f7 /scripts
parentc46e0d0bb7dffb5b2aafd0c07d0f693ba042b88d (diff)
Support arbitrary loading of format modules.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/MarkdownBook/Book.pm19
-rw-r--r--scripts/MarkdownBook/Document/html.pm (renamed from scripts/MarkdownBook/Document/HTML.pm)2
-rw-r--r--scripts/MarkdownBook/Document/txt.pm (renamed from scripts/MarkdownBook/Document/Txt.pm)2
3 files changed, 10 insertions, 13 deletions
diff --git a/scripts/MarkdownBook/Book.pm b/scripts/MarkdownBook/Book.pm
index f942803..572fb53 100644
--- a/scripts/MarkdownBook/Book.pm
+++ b/scripts/MarkdownBook/Book.pm
@@ -30,17 +30,14 @@ sub new
$self = {};
bless($self, $class);
- if ($format eq 'html') {
- use MarkdownBook::Document::HTML;
- $self->{'format'} = 'html';
- $self->{'format_mod'} = 'HTML';
- } elsif ($format eq 'txt') {
- use MarkdownBook::Document::Txt;
- $self->{'format'} = 'txt';
- $self->{'format_mod'} = 'Txt';
- } else {
- croak('Unsupported format "' . $format . '"');
+ unless ($format =~ m/^[a-z]+/) {
+ Carp::croak('Invalid format "' . $format . '"');
}
+ eval {
+ require 'MarkdownBook/Document/' . $format . '.pm';
+ 1;
+ } or Carp::croak('Unsupported format "' . $format . '"');
+ $self->{'format'} = $format;
$self->{'dir'} = $dir;
$self->{'docs'} = [];
@@ -96,7 +93,7 @@ sub _get_document_module
{
my ($self) = @_;
- return 'MarkdownBook::Document::' . $self->{'format_mod'};
+ return 'MarkdownBook::Document::' . $self->{'format'};
}
sub create_documents
diff --git a/scripts/MarkdownBook/Document/HTML.pm b/scripts/MarkdownBook/Document/html.pm
index 2852e8e..5ee1e79 100644
--- a/scripts/MarkdownBook/Document/HTML.pm
+++ b/scripts/MarkdownBook/Document/html.pm
@@ -23,7 +23,7 @@ use Text::Markdown;
use HTML::TreeBuilder;
use HTML::Template;
-package MarkdownBook::Document::HTML;
+package MarkdownBook::Document::html;
our @ISA = qw(MarkdownBook::Document);
diff --git a/scripts/MarkdownBook/Document/Txt.pm b/scripts/MarkdownBook/Document/txt.pm
index cf65d92..3ffd9cd 100644
--- a/scripts/MarkdownBook/Document/Txt.pm
+++ b/scripts/MarkdownBook/Document/txt.pm
@@ -19,7 +19,7 @@ use warnings;
use MarkdownBook::Document;
use Carp;
-package MarkdownBook::Document::Txt;
+package MarkdownBook::Document::txt;
our @ISA = qw(MarkdownBook::Document);