2009年9月6日星期日

[PerlChina] Fwd: 关于Perl的attributes的用法



---------- Forwarded message ----------
From: Mike.G <hylinux@gmail.com>
Date: 2009/9/7
Subject: Re: 关于Perl的attributes的用法
To: china-pm@pm.org


attributes的用法还是不太明白。
还是得需要各位提点一下。主要是到底是怎么用的。
其实C:A::Plugin::ActionDispatch倒是一个实例,可惜没怎么看明白。
好像是根据attributes调用相应的设置好的子过程。
主要是attributes会取得一个列表,然后匹配。

另外代码里需要的功能倒是搞定了。

主要是C:A::Plugin::ActionDispatch没有打断原来的model


2009/9/7 Mike.G <hylinux@gmail.com>

今天在使用一个C:A的插件的时候碰到一个问题:
C:A:Plugin::ActionDispatch

这个模块是使用attributes的特性来判断runmode的

有个问题是
例如:
when I define some runmode in parent class.
just like

package  Myparentclass;
use base qw/CGI::Applicatin/;
use CGI::Application::plugin::
ActionDispatch;

sub cgiapp_prerun {
     my $this = shift;
     if ( some condition ) {
       $this->prerun_mode('mode1');

    }

}


sub mode1:Runmode {
 it is here

}

1;

and in
Child Class

package MyChild;
use base qw/Myparentclass/;



1;

when the "some condition" true,  in parent class, it will be run mode1,
but it doesn't work:
said:
No such run mode 'showcity' at /home/ghw/myperl/in-marry/app/store line 13

但是把这个runmode定义在store的模块中可以的。
所以我猜测是C:A:Plugin::ActionDispatch中有问题了。
打开源代码看了一下。发现整个核心是使用attributes来做的。

一直没明白attributes的作用。
哪位大大可以讲讲?
看了一下perldoc,不太明白。

谢谢


Mike.G





--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
 要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
 要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛

-~----------~----~----~----~------~----~------~--~---

没有评论: