Perl: Static vs Package methods -
i need create package used other developers. best way implement static methods? static (class) methods must expect 1st parameter $class, , method must called class method:
my::package->sub1();
from other hand can write "regular" package subroutine (no $class parameter expected) same, needs called differently
my::package::sub1();
so, there no difference business functionality perspective (at least don't see it, except package name availability through first parameter), 2 different ways implement , call. kinda confusing. way should use , when? there rule? also, should check if method called expected (static vs package)?
first, functional point: if 2nd class create inherits my::package
, child::class::sub1()
undefined, , if sub1
written non-oo subroutine, child::class->sub1()
ignore fact it's being called child::class
.
as such, sake of programmers using module, you'll want make of subroutines in package/class respond consistent calling structure/methodology. module should either library of subroutines/functions or class full of methods. if part of oo, make oo. possible create subroutines behave in mixed mode, complicates code unnecessarily, , seems have gone out of fashion on cpan.
now if there no reason distinguish between my::package->sub1()
, child::class->sub1()
, can feel free ignore implicit class name parameter you'll passed. doesn't mean shouldn't expect parameter or should encourage non-oo call format in oo module.
Comments
Post a Comment