/usr/local/perl/lib/site_perl/5.8.5/Class/C3/Componentised.pm


NAME

Class::C3::Componentised


DESCRIPTION

Load mix-ins or components to your C3-based class.


SYNOPSIS

  package MyModule;
  use strict;
  use warnings;
  use base 'Class::C3::Componentised';
  sub component_base_class { "MyModule::Component" }
  package main;
  MyModule->load_components( qw/Foo Bar/ ); 
  # Will load MyModule::Component::Foo an MyModule::Component::Bar


DESCRIPTION

This will inject base classes to your module using the the Class::C3 manpage method resolution order.

Please note: these are not plugins that can take precedence over methods declared in MyModule. If you want something like that, consider the MooseX::Object::Pluggable manpage.


METHODS

load_components( @comps )

Loads the given components into the current module. If a module begins with a + character, it is taken to be a fully qualified class name, otherwise $class->component_base_class is prepended to it.

Calling this will call Class::C3::reinitialize.

load_own_components( @comps )

Simialr to load_components, but assumes every class is "$class::$comp".

load_optional_components

As load_components, but will silently ignore any components that cannot be found.

ensure_class_loaded

Given a class name, tests to see if it is already loaded or otherwise defined. If it is not yet loaded, the package is require'd, and an exception is thrown if the class is still not loaded.

 BUG: For some reason, packages with syntax errors are added to %INC on
      require
=cut

# # TODO: handle ->has_many('rel', 'Class'...) instead of # ->has_many('rel', 'Some::Schema::Class'...) # sub ensure_class_loaded { my ($class, $f_class) = @_;

  croak "Invalid class name $f_class"
      if ($f_class=~m/(?:\b:\b|\:{3,})/);
  return if Class::Inspector->loaded($f_class);
  my $file = $f_class . '.pm';
  $file =~ s{::}{/}g;
  eval { CORE::require($file) }; # require needs a bareword or filename
  if ($@) {
    if ($class->can('throw_exception')) {
      $class->throw_exception($@);
    } else {
      croak $@;
    }
  }
}

ensure_class_found

Returns true if the specified class is installed or already loaded, false otherwise

inject_base

Does the actual magic of adjusting @ISA on the target module.


AUTHOR

Matt S. Trout and the DBIx::Class team

Pulled out into seperate module by Ash Berlin <ash@cpan.org>


LICENSE

You may distribute this code under the same terms as Perl itself.

 /usr/local/perl/lib/site_perl/5.8.5/Class/C3/Componentised.pm