| 1 | package App::Pocoirc::ReadLine; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | $App::Pocoirc::ReadLine::AUTHORITY = 'cpan:HINRIK'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||
| 6 | 1 | $App::Pocoirc::ReadLine::VERSION = '0.47'; | |||||||||||||||||||||||||||
| 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::IRC::Plugin qw(PCI_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
| |||||||||||||||||||||||||||||
| 23 | 0 | my $self = bless { @_ }, $package; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | return $self; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $irc, %args) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | $self->{registered}++; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($self->{registered} == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | POE::Session->create( | ||||||||||||||||||||||||||||
| 35 | object_states => [ | ||||||||||||||||||||||||||||
| 36 | $self => [qw( | ||||||||||||||||||||||||||||
| 37 | _start | ||||||||||||||||||||||||||||
| 38 | got_user_input | ||||||||||||||||||||||||||||
| 39 | got_output | ||||||||||||||||||||||||||||
| 40 | restore_stdio | ||||||||||||||||||||||||||||
| 41 | )], | ||||||||||||||||||||||||||||
| 42 | ], | ||||||||||||||||||||||||||||
| 43 | 0 | args => [$args{network}], | |||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (!defined $self->{ui_irc}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $self->{ui_irc} = $irc; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | $self->{ircs}{$args{network}} = $irc; | |||||||||||||||||||||||||||
| 52 | 0 | $irc->plugin_register($self, 'SERVER', 'network'); | |||||||||||||||||||||||||||
| 53 | 0 | return 1; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ($self, $irc, %args) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | $self->{registered}--; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($self->{registered} == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | $poe_kernel->call($self->{session_id}, 'restore_stdio'); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | return 1; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($kernel, $session, $self, $network) = @_[KERNEL, SESSION, OBJECT, ARG0]; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | $self->{session_id} = $session->ID(); | |||||||||||||||||||||||||||
| 69 | 0 | $self->{console} = POE::Wheel::ReadLine->new( | |||||||||||||||||||||||||||
| 70 | InputEvent => 'got_user_input', | ||||||||||||||||||||||||||||
| 71 | PutMode => 'immediate', | ||||||||||||||||||||||||||||
| 72 | AppName => 'pocoirc', | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my ($stdout, $stderr) = wrap_output(); | |||||||||||||||||||||||||||
| 76 | 0 | $self->{stderr_reader} = POE::Wheel::ReadWrite->new( | |||||||||||||||||||||||||||
| 77 | Handle => $stderr, | ||||||||||||||||||||||||||||
| 78 | InputEvent => 'got_output', | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | 0 | $self->{stdout_reader} = POE::Wheel::ReadWrite->new( | |||||||||||||||||||||||||||
| 81 | Handle => $stdout, | ||||||||||||||||||||||||||||
| 82 | InputEvent => 'got_output', | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | $self->{console}->get("$network> "); | |||||||||||||||||||||||||||
| 86 | 0 | return; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub got_output { | ||||||||||||||||||||||||||
|
Subroutine
got_output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my ($self, $line) = @_[OBJECT, ARG0]; | |||||||||||||||||||||||||||
| 91 | 0 | $self->{console}->put($line); | |||||||||||||||||||||||||||
| 92 | 0 | return; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub got_user_input { | ||||||||||||||||||||||||||
|
Subroutine
got_user_input: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | my ($self, $line, $ex) = @_[OBJECT, ARG0, ARG1]; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if (defined $ex && $ex eq 'interrupt') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ex and $ex eq "interrupt"
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"
| |||||||||||||||||||||||||||||
| 99 | 0 | $self->{Pocoirc}->shutdown('Exiting due to user interruption'); | |||||||||||||||||||||||||||
| 100 | 0 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (defined $line && length $line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $line and length $line
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
| |||||||||||||||||||||||||||||
| 104 | 0 | $self->{console}->add_history($line); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (my ($new_network) = $line =~ /^network\s*(.+)/) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 107 | 0 | my $found; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | while (my ($network, $irc) = each %{ $self->{ircs} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($network =~ /^\Q$new_network\E$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $self->{ui_irc} = $irc; | |||||||||||||||||||||||||||
| 111 | 0 | $self->{console}->get("$network> "); | |||||||||||||||||||||||||||
| 112 | 0 | $found = 1; | |||||||||||||||||||||||||||
| 113 | 0 | last; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $self->_print_networks() if !$found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | elsif ($line =~ /^networks\s*$/) { | ||||||||||||||||||||||||||||
| 119 | 0 | $self->_print_networks(); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | elsif (my ($feature) = $line =~ /^(verbose|trace)\s*$/) { | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($self->{Pocoirc}->$feature()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->{Pocoirc}->$feature(0); | |||||||||||||||||||||||||||
| 124 | 0 | print "Disabled '$feature'\n"; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||
| 127 | 0 | $self->{Pocoirc}->$feature(1); | |||||||||||||||||||||||||||
| 128 | 0 | print "Enabled '$feature'\n"; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | elsif (my ($cmd, $args) = $line =~ m{^/([a-z_]+)\s*(.+)?}) { | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my @args = defined $args ? eval $args : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | $self->{ui_irc}->yield($cmd, @args); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | elsif (my ($method, $params) = $line =~ m{^\.([a-z_]+)\s*(.+)?}) { | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my @params = defined $params ? eval $params : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | local ($@, $!); | |||||||||||||||||||||||||||
| 139 | 0 | eval { | |||||||||||||||||||||||||||
| 140 | 0 | print dump($self->{ui_irc}->$method(@params)), "\n"; | |||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | chomp $err; | |||||||||||||||||||||||||||
| 144 | 0 | my $our_file = __FILE__; | |||||||||||||||||||||||||||
| 145 | 0 | $err =~ s{ at \Q$our_file\E line [0-9]+\.$}{}; | |||||||||||||||||||||||||||
| 146 | 0 | warn $err, "\n"; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||
| 150 | 0 | $self->_print_help(); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | $self->{console}->get(); | |||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub _print_help { | ||||||||||||||||||||||||||
|
Subroutine
_print_help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 159 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | print <<'EOF'; | |||||||||||||||||||||||||||
| 162 | Type "network foo" to switch networks, or "networks" for a list of networks. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Type ".foo 'bar', 'baz'" to call the method "foo" with the arguments 'bar' | ||||||||||||||||||||||||||||
| 165 | and 'baz' on the IRC component. You must quote your arguments since they | ||||||||||||||||||||||||||||
| 166 | will be eval'd, and don't forget to use commas between arguments. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Type "/foo 'bar', 'baz'" to call the POE::Component::IRC command foo with the | ||||||||||||||||||||||||||||
| 169 | arguments 'bar' and 'baz'. This is equivalent to: .yield 'foo', 'bar', 'baz' | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Type "verbose" and "trace" to flip those features on/off. | ||||||||||||||||||||||||||||
| 172 | EOF | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | return; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _print_networks { | ||||||||||||||||||||||||||
|
Subroutine
_print_networks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 179 | 0 | print "Available networks: ", join(', ', keys %{ $self->{ircs} }), "\n"; | |||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub S_network { | ||||||||||||||||||||||||||
|
Subroutine
S_network: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 184 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 185 | 0 | my $network = ${ $_[0] }; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | $self->{console}->get("$network> "); | |||||||||||||||||||||||||||
| 188 | 0 | for my $net (keys %{ $self->{ircs} }) { | |||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($self->{ircs}{$net} == $irc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | delete $self->{ircs}{$net}; | |||||||||||||||||||||||||||
| 191 | 0 | $self->{ircs}{$network} = $irc; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub restore_stdio { | ||||||||||||||||||||||||||
|
Subroutine
restore_stdio: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 198 | 0 | my ($self) = $_[OBJECT]; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | unwrap_output(); | |||||||||||||||||||||||||||
| 201 | 0 | delete $self->{console}; | |||||||||||||||||||||||||||
| 202 | 0 | delete $self->{stderr_reader}; | |||||||||||||||||||||||||||
| 203 | 0 | delete $self->{stdout_reader}; | |||||||||||||||||||||||||||
| 204 | 0 | return; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1 | 1; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =encoding utf8 | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head1 NAME | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | App::Pocoirc::ReadLine - A PoCo-IRC plugin which provides a ReadLine UI | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | This plugin is used internally by L<App::Pocoirc|App::Pocoirc>. No need for | ||||||||||||||||||||||||||||
| 218 | you to use it. | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =cut | ||||||||||||||||||||||||||||