Description: Behave as a module if used as one
Author: Joey Hess <joeyh@debian.org>
Origin: vendor, https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=356143;filename=markdown-md;msg=17
Bug-Debian: https://bugs.debian.org/356143
Forwarded: no
Reviewed-by: Matt Kraai <kraai@debian.org>
Last-Update: 2006-03-10
---
 Markdown.pl | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/Markdown.pl b/Markdown.pl
index 6e92f4a..3319e50 100755
--- a/Markdown.pl
+++ b/Markdown.pl
@@ -64,6 +64,9 @@ my %g_html_blocks;
 # (see _ProcessListItems() for details):
 my $g_list_level = 0;
 
+# Check to see if Markdown.pm has been loaded; if so we must be loaded
+# as a perl module.
+my $g_perl_module = exists $INC{'Markdown.pm'};
 
 #### Blosxom plug-in interface ##########################################
 
@@ -87,8 +90,8 @@ sub story {
 
 
 #### Movable Type plug-in interface #####################################
-eval {require MT};  # Test to see if we're running in MT.
-unless ($@) {
+eval {require MT} unless $g_perl_module;  # Test to see if we're running in MT.
+unless ($g_perl_module || $@) {
     require MT;
     import  MT;
     require MT::Template::Context;
@@ -178,7 +181,7 @@ unless ($@) {
 		});
 	}
 }
-else {
+elsif (! $g_perl_module) {
 #### BBEdit/command-line text filter interface ##########################
 # Needs to be hidden from MT (and Blosxom when running in static mode).
 
@@ -189,7 +192,7 @@ else {
 
 		#### Check for command-line switches: #################
 		my %cli_opts;
-		use Getopt::Long;
+		eval {use Getopt::Long}; # don't load in library mode
 		Getopt::Long::Configure('pass_through');
 		GetOptions(\%cli_opts,
 			'version',
@@ -1325,14 +1328,15 @@ __END__
 
 =head1 NAME
 
-B<Markdown>
+B<markdown>
 
 
 =head1 SYNOPSIS
 
-B<Markdown.pl> [ B<--html4tags> ] [ B<--version> ] [ B<-shortversion> ]
-    [ I<file> ... ]
+B<markdown> [ B<--html4tags> ] [ B<--version> ] [ B<-shortversion> ] [ I<file> ... ]
 
+use Markdown;
+$html=Markdown::Markdown($text);
 
 =head1 DESCRIPTION
 
@@ -1355,7 +1359,7 @@ For more information about Markdown's syntax, see:
 
 Use "--" to end switch parsing. For example, to open a file named "-z", use:
 
-	Markdown.pl -- -z
+	markdown -- -z
 
 =over 4
 
-- 
2.43.0

