2009年7月6日星期一

object-oriented coding in perl

Well, even if I don't want to admit, writing object-oriented code in Perl is painful without using any modules. Function "Bless" provides basic object ability, but when it comes to other features just like "inside-out object, private methods, easy-coding accessors", bless is not enough.

That's why there are so many modules on CPAN providing object-oriented feature for Perl. Class::InsideOut, Object::InsideOut,Class::Struct, Class::Methodmaker, Class::Generate etc.. Class::Accessor may be the simplest and easiest module for "easy-coding accessors". However, when I was writing my module"Net::Douban", I found setting default value for the feilds for the package is so important, which Class::Accessor dose not provide. So I spent some time hacking on this module, and wrote a module called "Class::Accessor::WithDefault" which can provide setting default value ability to Class::Accessor. It has some drawbacks because Class::Accessor using "Closure" to build the accessor and mutator but I think it is useful, right now it can be found at github here. Then I submitted this module request to CPA, sadly some days passed and I got no return message from that side.

By the way, after some coding experience with "Net::Douban", I realized that Moose should be the best choice for a Perl Progammer to write object-oriented code.

Posted via email from redicaps's posterous

没有评论: