NAME

Mock::Data::Plugin - Optional base class for Plugins

DESCRIPTION

Mock::Data plugins do not need to inherit from this class. Mock::Data determines whether a package is a plugin by whether it has a method apply_mockdata_plugin. There is no behavior to inherit, either; a plugin may make any changes it likes to the Mock::Data instance it was given, and the tools to make these changes can be found in the Mock::Data::Util package.

The process of loading a plugin is exactly:

  require $plugin_class;
  $mock= $plugin_class->apply_mockdata_plugin($mock);

EXTENDING

If you do inherit from this class, you get the benefits of Exporter::Extensible, and @CARP_NOT linkage that makes Carp errors point to the code that called into Mock::Data rather than the code of Mock::Data that called your plugin's function.

  package Mock::Data::Plugin::MyPlugin;
  use Mock::Data::Plugin -exporter_setup => 1;
  sub apply_mockdata_plugin {
    my $mock= shift;
    ...
  }

The most common things a plugin might do in that method are:

Add Generators

Generators added by a plugin should include the scope of the package, like

  $mock->add_generators( 'MyPlugin::something' => \&something );

This will automatically add that generator as both the name 'MyPlugin::soomething' and 'something' if the name was not already taken. By adding both, other modules can reference the namespaced name when they specifically need it, rather than whatever mix of generators are merged under the generic name or whichever module claimed it first.

Add Parent Classes

If Mock::Data were based on Moo, this would be possible by adding Roles to the object. A similar mechanism is provided by "mock_data_subclas" in Mock::Data::Util, which re-blesses the Mock::Data instance to include other parent classes. This allows you to directly add methods to Mock::Data. Be careful not to use nouns when adding methods, because generators use this same method namespace.

AUTHOR

Michael Conrad <mike@nrdvana.net>

VERSION

version 0.03

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Michael Conrad.

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