From 7863497dde842b1ab30a7a74c76f150a8424d74b Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 12 Aug 2012 14:26:02 -0400 Subject: Support arbitrary loading of format modules. --- 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); -- cgit v0.9.1