GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Devel::InheritNamespace(3) User Contributed Perl Documentation Devel::InheritNamespace(3)

Devel::InheritNamespace - Inherit An Entire Namespace

    use Devel::InheritNamespace;

    my $din = Devel::InheritNamespace->new(
        on_class_found => sub { ... },
    );
    my @modules = 
        $din->all_modules( 'MyApp', 'Parent::Namespace1', 'Parent::Namespace2' );

WARNING: YMMV using this module.

This module allows you to dynamically "inherit" an entire namespace.

For example, suppose you have a set of packages under MyApp::Base:

    MyApp::Base::Foo
    MyApp::Base::Bar
    MyApp::Base::Baz

Then some time later you start writing MyApp::Extend. You want to reuse MyApp::Base::Foo and MyApp::Base::Bar by subclassing (because somehow the base namespace matters -- say, in Catalyst), but you want to put a little customization for MyApp::Base::Baz

Normally you achieve this by manually creating MyApp::Extended:: modules:

    # in MyApp/Extended/Foo.pm
    package MyApp::Extended::Foo;
    use Moose;
    extends 'MyApp::Base::Foo';

    # in MyApp/Extended/Bar.pm
    package MyApp::Extended::Bar;
    use Moose;
    extends 'MyApp::Base::Bar';

    # in MyApp/Extended/Baz.pm
    package MyApp::Extended::Baz;
    use Moose;
    extends 'MyApp::Base::Baz';

    ... whatever customization you need ...

This is okay for a small number of modules, or if you are only doing this once or twice. But perhaps you have tens of these modules, or maybe you do this on every new project you create to inherit from a base applicatin set.

In that case you can use Devel::InheritNamespace.

Constructs a new Devel::InheritNamespace instance. You may pass the following options:
except
Regular expression to stop certain modules to be included in the search list. Note: This option will probably be deleted in the future releases: see "search_options" and Module::Pluggable for a way to achieve this.
on_class_found
Callback that gets called when a new class was loaded.
search_options
Extra arguments to pass to Module::Pluggable::Object to search for modules.

Loads modules based on the following heuristics:

    1. Search all modules in $main_namespace using Module::Pluggable.
    2. Load those modules
    3. Repease searching in namespaces declared in the @namespaces_to_inherit
    4. Check if the corresponding module in the $main_namespace exists.
       (we basically do $class =~ s/^$current_namespace/$main_namespace/)
    5. If the module is already loaded, skip and check the module
    6. If the module has not been loaded, dynamically create a module in
       the $main_namespace, inheriting from the original one.
    7. Repeat above for all namespaces.

Documentation. Samples. Tests.

Daisuke Maki "<daisuke@endeworks.jp>"

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.