File Coverage

blib/lib/Raisin/Plugin.pm
Criterion Covered Total %
statement 30 35 85.7
branch 4 8 50.0
condition n/a
subroutine 8 9 88.8
pod 2 4 50.0
total 44 56 78.5


line stmt bran cond sub pod time code
1             #!perl
2             #PODNAME: Raisin::Plugin
3             #ABSTRACT: Base class for Raisin plugins
4              
5 11     11   4861 use strict;
  11         24  
  11         321  
6 11     11   54 use warnings;
  11         55  
  11         468  
7              
8             package Raisin::Plugin;
9             $Raisin::Plugin::VERSION = '0.92';
10 11     11   140 use Carp;
  11         146  
  11         2413  
11              
12             sub new {
13 11     11 0 640 my ($class, $app) = @_;
14 11         35 my $self = bless {}, $class;
15 11         65 $self->{app} = $app;
16 11         51 $self;
17             }
18              
19 57     57 0 967 sub app { shift->{app} }
20              
21             sub build {
22 1     1 1 11 my ($self, %args) = @_;
23             }
24              
25             sub register {
26 10     10 1 457 my ($self, %items) = @_;
27              
28 10         75 while (my ($name, $item) = each %items) {
29 11     11   134 no strict 'refs';
  11         25  
  11         2924  
30             #no warnings 'redefine';
31              
32 16         71 my $class = ref $self->app;
33 16         39 my $caller = $self->app->{caller};
34              
35 16         46 my $glob = "${class}::${name}";
36 16 50       53 my $app_glob = $caller ? "${caller}::${name}" : undef;
37              
38 16 50       39 if ($self->app->can($name)) {
39 0         0 croak "Redefining of $glob not allowed";
40             }
41              
42 16 50       70 if (ref $item eq 'CODE') {
43 16         28 *{$glob} = $item;
  16         55  
44 16 50       44 *{$app_glob} = $item if $app_glob;
  16         140  
45             }
46             else {
47 0           $self->app->{$name} = $item;
48 0     0     *{$glob} = sub { shift->{$name} };
  0            
  0            
49             }
50             }
51             }
52              
53             1;
54              
55             __END__