diff -ur CGI-Wiki-Formatter-Multiple-0.01/lib/CGI/Wiki/Formatter/Multiple.pm CGI-Wiki-Formatter-Multiple-changed/lib/CGI/Wiki/Formatter/Multiple.pm --- CGI-Wiki-Formatter-Multiple-0.01/lib/CGI/Wiki/Formatter/Multiple.pm Mon Sep 22 16:09:33 2003 +++ CGI-Wiki-Formatter-Multiple-changed/lib/CGI/Wiki/Formatter/Multiple.pm Wed Sep 15 15:19:23 2004 @@ -96,8 +96,29 @@ sub format { my ($self, $raw, $wiki, $metadata) = @_; - my $formatter_label = $metadata->{formatter}[0] || "_DEFAULT"; - return $self->{formatters}{$formatter_label}->format( $raw, $wiki ); + return $self->_formatter($metadata)->format($raw, $wiki); +} + +=item B + +=cut + +sub find_internal_links { + my ($self, $raw, $metadata) = @_; + return () unless $self->_formatter($metadata); + return () unless $self->_formatter($metadata)->can("find_internal_links"); + return $self->_formatter($metadata)->find_internal_links($raw, $metadata); +} + +# internal method to return the correct formatter for the current +# page. + +sub _formatter { + my $self = shift; + my $metadata = shift; + my $label = $metadata->{formatter} || "_DEFAULT"; + $label = $label->[0] if ref($label); + return $self->{formatters}{$label} || $self->{formatters}{_DEFAULT}; } =back diff -ur CGI-Wiki-Formatter-Multiple-0.01/t/02_multiple_formatters.t CGI-Wiki-Formatter-Multiple-changed/t/02_multiple_formatters.t --- CGI-Wiki-Formatter-Multiple-0.01/t/02_multiple_formatters.t Mon Sep 22 16:08:27 2003 +++ CGI-Wiki-Formatter-Multiple-changed/t/02_multiple_formatters.t Wed Sep 15 15:19:12 2004 @@ -5,7 +5,7 @@ use CGI::Wiki::Formatter::Multiple; use vars qw( $num_sqlite_tests ); BEGIN { - $num_sqlite_tests = 5; + $num_sqlite_tests = 7; } use Test::More tests => 1 + $num_sqlite_tests; @@ -31,7 +31,7 @@ my $wiki = CGI::Wiki->new( store => $store, formatter => $formatter ); isa_ok( $wiki, "CGI::Wiki" ); - $wiki->write_node( "Normal Node", "foo bar", undef, + $wiki->write_node( "Normal Node", "foo bar FooBar", undef, { formatter => "normal" } ) or die "Can't write node"; $wiki->write_node( "UC Node", "foo bar", undef, { formatter => "uc" } ) or die "Can't write node"; @@ -39,7 +39,7 @@ my %data1 = $wiki->retrieve_node( "Normal Node" ); my $output1 = $wiki->format( $data1{content}, $data1{metadata} ); - like( $output1, qr|

\s*foo bar\s*

|, + like( $output1, qr|\Q

foo bar FooBar

|, "'normal' node formatted as expected" ); my %data2 = $wiki->retrieve_node( "UC Node" ); @@ -58,6 +58,12 @@ my %data4 = $wiki->retrieve_node( "Other Node" ); my $output4 = $wiki->format( $data4{content}, $data4{metadata} ); like( $output4, qr|

\s*foo bar\s*

|, "default _DEFAULT as expected" ); + + ok( $formatter->can("find_internal_links"), + "formatter can find_internal_links" ); + + my @links = $formatter->find_internal_links( $data1{content}, $data1{metadata} ); + is_deeply(\@links, [ 'FooBar' ], "links are correct"); } # end of SKIP