[Israel.pm] Moose static functions?

Yuval Kogman nothingmuch at woobling.org
Mon May 18 21:17:53 PDT 2009


2009/5/4 Shmuel Fomberg <semuelf at 012.net.il>:

> I've been looking on Moose lately, and was wandering about static
> functions.

Functions or class methods?

Class methods just work normally.

Functoins are potentially methods (or vice versa), just as in normal perl.

No difference really from a "traditional" class.

> I read an explanation by one of the developers about static variables,
> and way it was not implemented in Moose itself,
>
> but was left for a MooseX extension. (that supply class_has, if I
> remember right)

MooseX::ClassAttribute. But the only reason to use it is laziness and
short sightedness in my opinion.

> But what about static functions? How are they live in a Moose class?

There's no way to tell them apart from normal methods so they are just there

> And what about exporting them (a la Exporter)?

That's certainly possible, but it's probably a much better idea to
have a separate .pm file and package for the exported routines.

I usually use Sub::Exporter.

For an example of how to mix the exports and the OO api in the same
.pm, see Devel::StringInfo for example

Cheers,
Yuval

P.S. sorry for belated reply, I've been ignoring my email for the past week


More information about the Perl mailing list