⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module::pluggable.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Module::Pluggable 3".TH Module::Pluggable 3 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Module::Pluggable \- automatically give your module the ability to have plugins.SH "SYNOPSIS".IX Header "SYNOPSIS"Simple use Module::Pluggable \-.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable;.Ve.PPand then later ....PP.Vb 4\&    use MyClass;\&    my $mc = MyClass\->new();\&    # returns the names of all plugins installed under MyClass::Plugin::*\&    my @plugins = $mc\->plugins();.Ve.SH "EXAMPLE".IX Header "EXAMPLE"Why would you want to do this? Say you have something that wants to pass anobject to a number of different plugins in turn. For example you may want to extract meta-data from every email you get sent and do somethingwith it. Plugins make sense here because then you can keep adding new meta data parsers and all the logic and docs for each one will be self contained and new handlers are easy to add without changing the core code. For that, you might do something like ....PP.Vb 1\&    package Email::Examiner;\&\&    use strict;\&    use Email::Simple;\&    use Module::Pluggable require => 1;\&\&    sub handle_email {\&        my $self  = shift;\&        my $email = shift;\&\&        foreach my $plugin ($self\->plugins) {\&            $plugin\->examine($email);\&        }\&\&        return 1;\&    }.Ve.PP\&.. and all the plugins will get a chance in turn to look at it..PPThis can be trivally extended so that plugins could save the emailsomewhere and then no other plugin should try and do that. Simply have it so that the \f(CW\*(C`examine\*(C'\fR method returns \f(CW1\fR if it has saved the email somewhere. You might also wnat to be paranoidand check to see if the plugin has an \f(CW\*(C`examine\*(C'\fR method..PP.Vb 4\&        foreach my $plugin ($self\->plugins) {\&            next unless $plugin\->can(\*(Aqexamine\*(Aq);\&            last if     $plugin\->examine($email);\&        }.Ve.PPAnd so on. The sky's the limit..SH "DESCRIPTION".IX Header "DESCRIPTION"Provides a simple but, hopefully, extensible way of having 'plugins' for your module. Obviously this isn't going to be the be all and end all ofsolutions but it works for me..PPEssentially all it does is export a method into your namespace that looks through a search path for .pm files and turn those into class names..PPOptionally it instantiates those classes for you..SH "ADVANCED USAGE".IX Header "ADVANCED USAGE"Alternatively, if you don't want to use 'plugins' as the method ....PP.Vb 2\&    package MyClass;\&    use Module::Pluggable sub_name => \*(Aqfoo\*(Aq;.Ve.PPand then later ....PP.Vb 1\&    my @plugins = $mc\->foo();.Ve.PPOr if you want to look in another namespace.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable search_path => [\*(AqAcme::MyClass::Plugin\*(Aq, \*(AqMyClass::Extend\*(Aq];.Ve.PPor directory.PP.Vb 1\&    use Module::Pluggable search_dirs => [\*(Aqmylibs/Foo\*(Aq];.Ve.PPOr if you want to instantiate each plugin rather than just return the name.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable instantiate => \*(Aqnew\*(Aq;.Ve.PPand then.PP.Vb 3\&    # whatever is passed to \*(Aqplugins\*(Aq will be passed \&    # to \*(Aqnew\*(Aq for each plugin \&    my @plugins = $mc\->plugins(@options);.Ve.PPalternatively you can just require the module without instantiating it.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable require => 1;.Ve.PPsince requiring automatically searches inner packages, which may not be desirable, you can turn this off.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable require => 1, inner => 0;.Ve.PPYou can limit the plugins loaded using the except option, either as a string,array ref or regex.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable except => \*(AqMyClass::Plugin::Foo\*(Aq;.Ve.PPor.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable except => [\*(AqMyClass::Plugin::Foo\*(Aq, \*(AqMyClass::Plugin::Bar\*(Aq];.Ve.PPor.PP.Vb 2\&    package MyClass;\&    use Module::Pluggable except => qr/^MyClass::Plugin::(Foo|Bar)$/;.Ve.PPand similarly for only which will only load plugins which match..PPRemember you can use the module more than once.PP.Vb 3\&    package MyClass;\&    use Module::Pluggable search_path => \*(AqMyClass::Filters\*(Aq sub_name => \*(Aqfilters\*(Aq;\&    use Module::Pluggable search_path => \*(AqMyClass::Plugins\*(Aq sub_name => \*(Aqplugins\*(Aq;.Ve.PPand then later ....PP.Vb 2\&    my @filters = $self\->filters;\&    my @plugins = $self\->plugins;.Ve.SH "INNER PACKAGES".IX Header "INNER PACKAGES"If you have, for example, a file \fBlib/Something/Plugin/Foo.pm\fR thatcontains package definitions for both \f(CW\*(C`Something::Plugin::Foo\*(C'\fR and \&\f(CW\*(C`Something::Plugin::Bar\*(C'\fR then as long as you either have either the \fBrequire\fR or \fBinstantiate\fR option set then we'll also find \&\f(CW\*(C`Something::Plugin::Bar\*(C'\fR. Nifty!.SH "OPTIONS".IX Header "OPTIONS"You can pass a hash of options when importing this module..PPThe options can be ....Sh "sub_name".IX Subsection "sub_name"The name of the subroutine to create in your namespace..PPBy default this is 'plugins'.Sh "search_path".IX Subsection "search_path"An array ref of namespaces to look in..Sh "search_dirs".IX Subsection "search_dirs"An array ref of directorys to look in before \f(CW@INC\fR..Sh "instantiate".IX Subsection "instantiate"Call this method on the class. In general this will probably be 'new'but it can be whatever you want. Whatever arguments are passed to 'plugins' will be passed to the method..PPThe default is 'undef' i.e just return the class name..Sh "require".IX Subsection "require"Just require the class, don't instantiate (overrides 'instantiate');.Sh "inner".IX Subsection "inner"If set to 0 will \fBnot\fR search inner packages. If set to 1 will override \f(CW\*(C`require\*(C'\fR..Sh "only".IX Subsection "only"Takes a string, array ref or regex describing the names of the only plugins to return. Whilst this may seem perverse ... well, it is. But it also makes sense. Trust me..Sh "except".IX Subsection "except"Similar to \f(CW\*(C`only\*(C'\fR it takes a description of plugins to exclude from returning. This is slightly less perverse..Sh "package".IX Subsection "package"This is for use by extension modules which build on \f(CW\*(C`Module::Pluggable\*(C'\fR:passing a \f(CW\*(C`package\*(C'\fR option allows you to place the plugin method in adifferent package other than your own..Sh "file_regex".IX Subsection "file_regex"By default \f(CW\*(C`Module::Pluggable\*(C'\fR only looks for \fI.pm\fR files..PPBy supplying a new \f(CW\*(C`file_regex\*(C'\fR then you can change this behaviour e.g.PP.Vb 1\&    file_regex => qr/\e.plugin$/.Ve.SH "METHODs".IX Header "METHODs".Sh "search_path".IX Subsection "search_path"The method \f(CW\*(C`search_path\*(C'\fR is exported into you namespace as well. You can call that at any time to change or replace the search_path..PP.Vb 2\&    $self\->search_path( add => "New::Path" ); # add\&    $self\->search_path( new => "New::Path" ); # replace.Ve.SH "FUTURE PLANS".IX Header "FUTURE PLANS"This does everything I need and I can't really think of any other features I want to add. Famous last words of course.PPRecently tried fixed to find inner packages and to make it \&'just work' with \s-1PAR\s0 but there are still some issues..PPHowever suggestions (and patches) are welcome..SH "AUTHOR".IX Header "AUTHOR"Simon Wistow <simon@thegestalt.org>.SH "COPYING".IX Header "COPYING"Copyright, 2006 Simon Wistow.PPDistributed under the same terms as Perl itself..SH "BUGS".IX Header "BUGS"None known..SH "SEE ALSO".IX Header "SEE ALSO"File::Spec, File::Find, File::Basename, Class::Factory::Util, Module::Pluggable::Ordered

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -