File Coverage

blib/lib/IPerl.pm
Criterion Covered Total %
statement 32 32 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 1 3 33.3
total 43 46 93.4


line stmt bran cond sub pod time code
1             package # hide from PAUSE
2             IPerl;
3              
4 2     2   90936 use strict;
  2         4  
  2         46  
5 2     2   8 use warnings;
  2         4  
  2         36  
6 2     2   364 use Moo;
  2         8778  
  2         16  
7             with qw( MooX::Singleton );
8              
9             our $REPL;
10             our $current_msg;
11              
12             has helpers => ( is => 'rw', default => sub { +{} } );
13              
14             sub helper {
15 18     18 1 40 my ($class, $name, $cb) = @_;
16 18         70 my $self = $class->instance;
17             warn (qq{Helper "$name" already exists, replacing.})
18 18 50       177 if exists $self->helpers->{$name};
19 18         37 $self->add_helper($name => $cb);
20             }
21              
22             sub add_helper {
23 18     18 0 31 my ($self, $name, $cb) = @_;
24 18         40 $self->helpers->{$name} = $cb;
25             {
26 2     2   1703 no strict 'refs';
  2         4  
  2         70  
  18         19  
27 2     2   11 no warnings 'redefine';
  2         3  
  2         153  
28 18         24 *{"IPerl::$name"} = $cb;
  18         97  
29             }
30             }
31              
32             sub load_plugin {
33 5     5 0 2102 my ($class, $plugin_name) = @_;
34 5         16 my $plugin_package = "Devel::IPerl::Plugin::$plugin_name";
35 2     2   10 { no strict; eval "require $plugin_package"; }
  2         3  
  2         97  
  5         6  
  5         272  
36 5         51 $plugin_package->register( $class );
37             }
38              
39             1;
40              
41             __END__
42              
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             IPerl
50              
51             =head1 VERSION
52              
53             version 0.008
54              
55             =head1 METHODS
56              
57             =head2 helper
58              
59             IPerl->helper( $name, $coderef )
60              
61             Register helper callback.
62              
63             =head1 AUTHOR
64              
65             Zakariyya Mughal <zmughal@cpan.org>
66              
67             =head1 COPYRIGHT AND LICENSE
68              
69             This software is copyright (c) 2014 by Zakariyya Mughal.
70              
71             This is free software; you can redistribute it and/or modify it under
72             the same terms as the Perl 5 programming language system itself.
73              
74             =cut