Pod::Simple::Methody -- 將 Pod::Simple 事件轉換為方法呼叫
require 5;
use strict;
package SomePodFormatter;
use base qw(Pod::Simple::Methody);
sub handle_text {
my($self, $text) = @_;
...
}
sub start_head1 {
my($self, $attrs) = @_;
...
}
sub end_head1 {
my($self) = @_;
...
}
...以及您想要捕捉的其他事件的 start_/end_ 方法。
這個類別對於撰寫基於 Pod::Simple 的 Pod 格式化程式的人來說很有用。
這個類別(非常小——請閱讀原始碼)覆寫了 Pod::Simple 的 _handle_element_start、_handle_text 和 _handle_element_end 方法,以便將解析器事件轉換為方法呼叫。(否則,這是 Pod::Simple 的子類別,並繼承其所有方法。)
您可以將這個類別用作 Pod 格式化程式/處理器的基底類別。
例如,當 Pod::Simple 看到「=head1 Hi there」時,它基本上會執行此操作
$parser->_handle_element_start( "head1", \%attributes );
$parser->_handle_text( "Hi there" );
$parser->_handle_element_end( "head1" );
但是,如果你建立 Pod::Simple::Methody 的子類別,它會在看到「=head1 Hi there」時執行此操作
$parser->start_head1( \%attributes ) if $parser->can('start_head1');
$parser->handle_text( "Hi there" ) if $parser->can('handle_text');
$parser->end_head1() if $parser->can('end_head1');
如果 Pod::Simple 傳送一個事件,其中元素名稱包含破折號、句點或冒號,對應的方法名稱會在它的位置加上底線。例如,「foo.bar:baz」會變成 start_foo_bar_baz 和 end_foo_bar_baz。
請參閱 Pod::Simple::Text 的原始碼,以取得使用此類別的範例。
Pod::Simple、Pod::Simple::Subclassing
有關 POD 和 Pod::Simple 的問題或討論,應傳送至 pod-people@perl.org 郵件清單。傳送一封空白電子郵件至 pod-people-subscribe@perl.org 以訂閱。
此模組在開放的 GitHub 儲存庫中管理,https://github.com/perl-pod/pod-simple/。歡迎分叉和貢獻,或複製 git://github.com/perl-pod/pod-simple.git 並傳送修補程式!
歡迎針對 Pod::Simple 的修補程式。請將錯誤報告傳送至 <bug-pod-simple@rt.cpan.org>。
著作權所有 (c) 2002 Sean M. Burke。
此函式庫是免費軟體;你可以根據 Perl 本身的條款重新散布或修改它。
散布此程式時,希望它對你有用,但沒有任何保證;甚至沒有對適銷性或特定用途適用性的默示保證。
Pod::Simple 由 Sean M. Burke <sburke@cpan.org> 建立。但不要打擾他,他已經退休了。
Pod::Simple 由以下人員維護
Allison Randal allison@perl.org
Hans Dieter Pearcey hdp@cpan.org
David E. Wheeler dwheeler@cpan.org