Pocosi/ReadLine.pm

filter: Statementstmt 36.6% 33 / 90 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 12 / 20 Podpod 0.0% 0 / 6 totaltotal 30.8% 45 / 146 CC 13 SCAR 40.9
CC
13
Cov
28%
got_user_input
156.0
new
6.0
PCSI_register
2.0
CRAP 59.6
↑ Summary Pocosi.pm »
1 package App::Pocosi::ReadLine;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $App::Pocosi::ReadLine::AUTHORITY = 'cpan:HINRIK';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $App::Pocosi::ReadLine::VERSION = '0.03';
7 }
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dump 'dump';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use IO::WrapOutput;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use POE::Component::Server::IRC::Plugin qw(PCSI_EAT_NONE);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use POE::Wheel::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use POE::Wheel::ReadWrite;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
21 0 my ($package) = shift;
22 0 ▶ croak "$package requires an even number of arguments" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
23 0 my $self = bless { @_ }, $package;
24 0 return $self;
25 }
26  
27 0 ▶sub PCSI_register {
Subroutine PCSI_register: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my ($self, $ircd, %args) = @_;
29 0 $self->{ircd} = $ircd;
30  
31 0 POE::Session->create(
32 object_states => [
33 $self => [qw(
34 _start
35 got_user_input
36 got_output
37 restore_stdio
38 )],
39 ],
40 );
41 0 return 1;
42 }
43  
44 0 ▶sub PCSI_unregister {
Subroutine PCSI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my ($self, $ircd, %args) = @_;
46 0 $poe_kernel->call($self->{session_id}, 'restore_stdio');
47 0 return 1;
48 }
49  
50 0 ▶sub _start {
Subroutine _start: not called CC=1 SCAR=6.9
51 0 my ($kernel, $session, $self) = @_[KERNEL, SESSION, OBJECT];
52  
53 0 $self->{session_id} = $session->ID();
54 0 $self->{console} = POE::Wheel::ReadLine->new(
55 InputEvent => 'got_user_input',
56 PutMode => 'immediate',
57 AppName => 'pocosi',
58 );
59  
60 0 my ($stdout, $stderr) = wrap_output();
61  
62 0 $self->{stderr_reader} = POE::Wheel::ReadWrite->new(
63 Handle => $stderr,
64 InputEvent => 'got_output',
65 );
66 0 $self->{stdout_reader} = POE::Wheel::ReadWrite->new(
67 Handle => $stdout,
68 InputEvent => 'got_output',
69 );
70  
71 0 $self->{console}->get();
72 0 return;
73 }
74  
75 0 ▶sub got_output {
Subroutine got_output: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ($self, $line) = @_[OBJECT, ARG0];
77 0 $self->{console}->put($line);
78 0 return;
79 }
80  
81 0 ▶sub got_user_input {
Subroutine got_user_input: not called CC=12 SCAR=50.5
Pod undocumented
82 0 my ($self, $line, $ex) = @_[OBJECT, ARG0, ARG1];
83  
84 0 ▶ if (defined $ex && $ex eq 'interrupt') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ex and $ex eq "interrupt") 0 0 0
Condition0%0/3
defined $ex and $ex eq "interrupt"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ex and $ex eq "interrupt"
defined $ex $ex eq "interrupt"
Truth table0%0/3
A and B
A= defined $exB= $ex eq "interrupt"
ABresult
0X0
100
111
85 0 $self->{Pocosi}->shutdown('Exiting due to user interruption');
86 0 return;
87 }
88  
89 0 ▶ if (defined $line && length $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line and length $line) 0 0 0
Condition0%0/3
defined $line and length $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table0%0/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
90 0 $self->{console}->add_history($line);
91  
92 0 ▶ if (my ($feature) = $line =~ /^(verbose|trace)\s*$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (my($feature) = $line =~ /^(verbose|trace)\s*$/) { } 0 0 0
elsif (() = $line =~ m[^/([a-z_]+)\s*(.+)?]) { } 0 0 0
elsif (() = $line =~ /^\.([a-z_]+)\s*(.+)?/) { } 0 0 0
93 0 ▶ if ($self->{Pocosi}->$feature()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Pocosi'}->$feature) { } 0 0 0
94 0 $self->{Pocosi}->$feature(0);
95 0 print "Disabled '$feature'\n";
96 }
97 else {
98 0 $self->{Pocosi}->$feature(1);
99 0 print "Enabled '$feature'\n";
100 }
101 }
102 elsif (my ($cmd, $args) = $line =~ m{^/([a-z_]+)\s*(.+)?}) {
103 0 ▶ my @args = defined $args ? eval $args : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 0 0 0
104 0 $self->{ircd}->yield($cmd, @args);
105 }
106 elsif (my ($method, $params) = $line =~ m{^\.([a-z_]+)\s*(.+)?}) {
107 0 ▶ my @params = defined $params ? eval $params : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $params ? : 0 0 0
108  
109 0 local ($@, $!);
110 0 eval {
111 0 print dump($self->{ircd}->$method(@params)), "\n";
112 };
113 0 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
114 0 chomp $err;
115 0 my $our_file = __FILE__;
116 0 $err =~ s{ at \Q$our_file\E line [0-9]+\.$}{};
117 0 warn $err, "\n";
118 }
119 }
120 else {
121 0 $self->_print_help();
122 }
123 }
124  
125 0 $self->{console}->get();
126 0 return;
127 }
128  
129 0 ▶sub _print_help {
Subroutine _print_help: not called CC=1 SCAR=6.9
130 0 my ($self) = @_;
131  
132 0 print <<'EOF';
133 Type ".foo 'bar', 'baz'" to call the method "foo" with the arguments 'bar'
134 and 'baz' on the IRCd component. You must quote your arguments since they
135 will be eval'd, and don't forget to use commas between arguments.
136  
137 Type "/foo 'bar', 'baz'" to call the POE::Component::Server::IRC command foo
138 with the arguments 'bar' and 'baz'. This is equivalent to: .yield 'foo',
139 'bar', 'baz'
140  
141 Type "verbose" and "trace" to flip those features on/off.
142 EOF
143  
144 0 return;
145 }
146  
147 0 ▶sub restore_stdio {
Subroutine restore_stdio: not called CC=1 SCAR=6.9
Pod undocumented
148 0 my ($self) = $_[OBJECT];
149  
150 0 unwrap_output();
151 0 delete $self->{console};
152 0 delete $self->{stderr_reader};
153 0 delete $self->{stdout_reader};
154 0 return;
155 }
156  
157 1 1;
158  
159 =encoding utf8
160  
161 =head1 NAME
162  
163 App::Pocosi::ReadLine - A PoCo-Server-IRC plugin which provides a ReadLine UI
164  
165 =head1 DESCRIPTION
166  
167 This plugin is used internally by L<App::Pocosi|App::Pocosi>. No need for
168 you to use it.
169  
170 =head1 AUTHOR
171  
172 Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
173  
174 =cut
↑ Summary Pocosi.pm »