diff options
-rw-r--r-- | scripts/MarkdownBook/Book.pm | 19 | ||||
-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); |