NAME

Chj::constructorexporter

SYNOPSIS

    {
        package Foo;
        use Chj::constructorexporter;
        *import= constructorexporter new=> "Foo", new_from_string=> "foo";
        sub new { ... }
    }
    use Foo "foo", "foo"; # or ":all"; 'use Foo;' would not import anything
    foo("abc") # calls Foo->new_from_string("abc")
    Foo(1,2) # calls Foo->new(1,2)

    {
        package Bar;
        our @ISA="Foo";
    }
    use Bar "foo"; # this exports a different "foo"!
    foo("def") # calls Bar->new("def")

    # to import both (avoiding conflict):
    use Foo qw(foo);
    use Bar qw(foo -prefix bar_); # imports 'bar_foo'
    # The position of the -prefix argument and its value within the
    # import list is irrelevant.

    # Note that the exported constructor functions cannot be reached by
    # full qualification: in this example Foo::foo is undefined (or it
    # might instead be an unrelated method definition)!

DESCRIPTION

This module might be evil: it helps writing OO modules that also export functions. It only helps to export functions that are constructors for the class in question, though, so its evilness might be bounded.

Subclasses that inherit (don't override) the import method will export constructors for the subclass those are imported from. That might be sensible or pure evil, the creator of this module isn't sure yet. If you don't like this, either override 'import' in the subclass, or ask for this to be changed.

NOTE

This is alpha software! Read the status section in the package README or on the website.