| 1 | package Froody::Invoker::PluginService; | ||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use base qw(Froody::Invoker::Implementation); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use Froody::Implementation; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | our $IMPLEMENTATION_SUPERCLASS = 1; | |||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Froody::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | my $logger = get_logger('froody.invoker.pluginservice'); | |||||||||
| 10 | |||||||||||
| 11 | 4 | __PACKAGE__->mk_accessors(qw( delegate_class plugin_impl )); | |||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Froody::Invoker::PluginService | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | # Loads the named module off of disk, or throws a nice error if | ||||||||||
| 22 | # it can't for some reason. Checks to see if the module supports | ||||||||||
| 23 | # the needed method name too. | ||||||||||
| 24 | 1 | ▶ | sub _require_module { | ||||||||
|
Subroutine
_require_module: called CC=5 SCAR=22.9
| |||||||||||
| 25 | 1 | my $self = shift; | |||||||||
| 26 | 1 | my $module_name = shift; | |||||||||
| 27 | 1 | my $method_name = shift; | |||||||||
| 28 | |||||||||||
| 29 | # are we already loaded? Sweet. | ||||||||||
| 30 | { | ||||||||||
| 31 | 4 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | return if %{"$module_name\::"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | } | ||||||||||
| 34 | # use the UNIVERSAL::require module to require the module | ||||||||||
| 35 | # this returns false if the require fails, but this can be _both_ because | ||||||||||
| 36 | # there were errors, _and_ if the file we expected doesn't exist, but | ||||||||||
| 37 | # handlers _might_ be defined in differently named files. | ||||||||||
| 38 | 0 | $module_name->require; | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | if ( $UNIVERSAL::require::ERROR ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | $logger->error("Error compiling module $module_name: $UNIVERSAL::require::ERROR"); | |||||||||
| 42 | 0 | Froody::Error->throw("perl.use", "module $module_name not found"); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | # now check to see if there is a package of the right name loaded. | ||||||||||
| 46 | { | ||||||||||
| 47 | 0 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||
| 48 | 0 | ▶ | unless (%{"$module_name\::"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | # no stash defined, thus there's no package with the right name loaded. | ||||||||||
| 50 | 0 | Froody::Error->throw("perl.use", "module $module_name does not exist"); | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | # if there was a syntax error, it looks like the stash _is_ defined, but | ||||||||||
| 55 | # the module won't be able to do a method call. | ||||||||||
| 56 | 0 | ▶ | unless ( $module_name->can($method_name) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | $logger->error("Error compiling module $module_name: $UNIVERSAL::require::ERROR"); | |||||||||
| 58 | 0 | Froody::Error->throw("perl.use", "module $module_name cannot '$method_name'"); | |||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | sub module { | ||||||||
|
Subroutine
module: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | 1 | my ($self, $method) = @_; | |||||||||
| 64 | |||||||||||
| 65 | # do a quick module conversion | ||||||||||
| 66 | 1 | my $module = $self->delegate_class; | |||||||||
| 67 | 1 | $self->_require_module($module, $method->name); | |||||||||
| 68 | |||||||||||
| 69 | 1 | return $module; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | ▶ | sub create_context { | ||||||||
|
Subroutine
create_context: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 1 | my $self = shift; | |||||||||
| 74 | 1 | return bless { }, $self->{plugin_impl}; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub source { | ||||||||
|
Subroutine
source: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 0 | return "plugin ". shift->SUPER::source() | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub pre_process { | ||||||||
|
Subroutine
pre_process: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 82 | 0 | my ($self, $method, $params) = @_; | |||||||||
| 83 | 0 | Froody::Implementation::pre_process($self->{plugin_impl}, $method, $params); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub post_process { | ||||||||
|
Subroutine
post_process: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | my ($self, $method, $params) = @_; | |||||||||
| 88 | 0 | Froody::Implementation::post_process($self->{plugin_impl}, $method, $params); | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub error_handler { | ||||||||
|
Subroutine
error_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 92 | 0 | my ($self, $method, $error) = @_; | |||||||||
| 93 | 0 | Froody::Implementation::error_handler($self->{plugin_impl}, $method, $error); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | =head1 AUTHOR | ||||||||||
| 98 | |||||||||||
| 99 | Copyright Fotango 2005. All rights reserved. | ||||||||||
| 100 | |||||||||||
| 101 | Please see the main L<Froody> documentation for details of who has worked | ||||||||||
| 102 | on this project. | ||||||||||
| 103 | |||||||||||
| 104 | This module is free software; you can redistribute it and/or modify it under | ||||||||||
| 105 | the same terms as Perl itself. | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | 4 | 1; | |||||||||