File Coverage

blib/lib/Devel/REPL/Plugin/Commands.pm
Criterion Covered Total %
statement 27 36 75.0
branch 1 2 50.0
condition n/a
subroutine 11 13 84.6
pod 0 3 0.0
total 39 54 72.2


line stmt bran cond sub pod time code
1 2     2   2210 use strict;
  2         4  
  2         60  
2 2     2   10 use warnings;
  2         5  
  2         115  
3             # ABSTRACT: Generic command creation plugin using injected functions
4              
5             our $VERSION = '1.003029';
6              
7             use Devel::REPL::Plugin;
8 2     2   12 use Scalar::Util qw(weaken);
  2         2  
  2         13  
9 2     2   8649 use namespace::autoclean;
  2         5  
  2         116  
10 2     2   14  
  2         3  
  2         18  
11             our $COMMAND_INSTALLER;
12              
13             has 'command_set' => (
14             is => 'ro',
15             lazy => 1, default => sub { {} }
16             );
17              
18             my ($self) = @_;
19             $self->load_plugin('Packages');
20 1     1 0 5 unless ($self->can('setup_commands')) {
21 1         7 $self->meta->add_method('setup_commands' => sub {});
22 1 50       180 }
23 1     1   8 }
        1      
24              
25             my ($self) = @_;
26             $self->setup_commands;
27             }
28 1     1 0 5  
29 1         5 after 'setup_commands' => sub {
30             my ($self) = @_;
31             weaken($self);
32             $self->command_set->{load_plugin} = sub {
33             my $self = shift;
34             sub { $self->load_plugin(@_); };
35             };
36             };
37              
38             my ($self) = @_;
39             my $command_set = $self->command_set;
40             my %command_subs = map {
41             ($_ => $command_set->{$_}->($self));
42 0     0 0   } keys %$command_set;
43 0           return sub {
44             my $package = shift;
45 0           foreach my $command (keys %command_subs) {
  0            
46             no strict 'refs';
47             no warnings 'redefine';
48 0     0     *{"${package}::${command}"} = $command_subs{$command};
49 0           }
50 2     2   738 };
  2         4  
  2         66  
51 2     2   19 }
  2         4  
  2         500  
52 0            
  0            
53             around 'mangle_line' => sub {
54 0           my ($orig, $self) = (shift, shift);
55             my ($line) = @_;
56             my $name = '$'.__PACKAGE__.'::COMMAND_INSTALLER';
57             return qq{BEGIN { ${name}->(__PACKAGE__) }\n}.$self->$orig(@_);
58             };
59              
60             around 'compile' => sub {
61             my ($orig, $self) = (shift, shift);
62             local $COMMAND_INSTALLER = $self->command_installer;
63             $self->$orig(@_);
64             };
65              
66             1;
67              
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Devel::REPL::Plugin::Commands - Generic command creation plugin using injected functions
76              
77             =head1 VERSION
78              
79             version 1.003029
80              
81             =head1 SUPPORT
82              
83             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL>
84             (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>).
85              
86             There is also an irc channel available for users of this distribution, at
87             L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>.
88              
89             =head1 AUTHOR
90              
91             Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>)
92              
93             =head1 COPYRIGHT AND LICENCE
94              
95             This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
96              
97             This is free software; you can redistribute it and/or modify it under
98             the same terms as the Perl 5 programming language system itself.
99              
100             =cut