| 1 | # You may distribute under the terms of the GNU General Public License | ||||||||||
| 2 | # | ||||||||||
| 3 | # (C) Paul Evans, 2008-2014 -- leonerd@leonerd.org.uk | ||||||||||
| 4 | |||||||||||
| 5 | package Circle; | ||||||||||
| 6 | |||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use base qw( Net::Async::Tangence::Server ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | IO::Async::Listener->VERSION( '0.64' ); # {handle_constructor} | |||||||||
| 11 | 4 | Net::Async::Tangence::Server->VERSION( '0.13' ); # Future-returning API | |||||||||
| 12 | |||||||||||
| 13 | 4 | our $VERSION = '0.173320'; | |||||||||
| 14 | |||||||||||
| 15 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 4 | ▶ | use Tangence::Registry 0.20; # Support for late-loading classes | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | use File::ShareDir qw( module_file ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 4 | ▶ | use IO::Async::OS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 4 | require Circle::RootObj; # must be late-bound, after $VERSION is set | |||||||||
| 24 | |||||||||||
| 25 | =head1 NAME | ||||||||||
| 26 | |||||||||||
| 27 | C<Circle> - server backend for the C<Circle> application host | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | sub new | ||||||||||
| 32 | 3 | ▶ | { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 33 | 3 | my $class = shift; | |||||||||
| 34 | 3 | my %args = @_; | |||||||||
| 35 | |||||||||||
| 36 | 3 | ▶ | my $loop = $args{loop} or croak "Need a loop"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 3 | my $registry = Tangence::Registry->new( | |||||||||
| 39 | tanfile => module_file( __PACKAGE__, "circle.tan" ), | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 3 | my $rootobj = $registry->construct( | |||||||||
| 43 | "Circle::RootObj", | ||||||||||
| 44 | loop => $loop | ||||||||||
| 45 | ); | ||||||||||
| 46 | 3 | ▶ | $rootobj->id == 1 or die "Assert failed: root object does not have ID 1"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 3 | my $self = $class->SUPER::new( | |||||||||
| 49 | registry => $registry, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 3 | $loop->add( $self ); | |||||||||
| 53 | |||||||||||
| 54 | 3 | $self->{rootobj} = $rootobj; | |||||||||
| 55 | |||||||||||
| 56 | 3 | return $self; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | sub make_local_client | ||||||||||
| 60 | 3 | ▶ | { | ||||||||
|
Subroutine
make_local_client: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | 3 | my $self = shift; | |||||||||
| 62 | |||||||||||
| 63 | 3 | my $loop = $self->loop; | |||||||||
| 64 | |||||||||||
| 65 | 3 | ▶ | my ( $S1, $S2 ) = IO::Async::OS->socketpair or die "Cannot socketpair - $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | # Internal hackery; stolen from IaListener | ||||||||||
| 68 | 3 | my $acceptor = $self->acceptor; | |||||||||
| 69 | 3 | my $handle = $self->{handle_constructor}->( $self ); | |||||||||
| 70 | 3 | $S1->blocking( 0 ); | |||||||||
| 71 | 3 | $handle->set_handle( $S1 ); | |||||||||
| 72 | 3 | $self->on_accept( $handle ); | |||||||||
| 73 | |||||||||||
| 74 | 3 | require Net::Async::Tangence::Client; | |||||||||
| 75 | 3 | my $client = Net::Async::Tangence::Client->new( | |||||||||
| 76 | handle => $S2, | ||||||||||
| 77 | identity => "test_client", | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | 3 | $loop->add( $client ); | |||||||||
| 81 | |||||||||||
| 82 | 3 | return $client; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | sub new_with_client | ||||||||||
| 86 | 3 | ▶ | { | ||||||||
|
Subroutine
new_with_client: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 3 | my $class = shift; | |||||||||
| 88 | |||||||||||
| 89 | 3 | my $self = $class->new( @_ ); | |||||||||
| 90 | |||||||||||
| 91 | 3 | my $client = $self->make_local_client; | |||||||||
| 92 | |||||||||||
| 93 | 3 | return ( $self, $client ); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | sub warn | ||||||||||
| 97 | 0 | ▶ | { | ||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 98 | 0 | my $self = shift; | |||||||||
| 99 | 0 | my $text = join " ", @_; | |||||||||
| 100 | 0 | chomp $text; | |||||||||
| 101 | |||||||||||
| 102 | 0 | my $rootobj = $self->{rootobj}; | |||||||||
| 103 | 0 | $rootobj->push_displayevent( warning => { text => $text } ); | |||||||||
| 104 | 0 | $rootobj->bump_level( 2 ); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | =head1 QUESTIONS | ||||||||||
| 108 | |||||||||||
| 109 | =head2 How do I connect to freenode.net #perl and identify with NickServ | ||||||||||
| 110 | |||||||||||
| 111 | # in Global tab | ||||||||||
| 112 | /networks add -type irc Freenode | ||||||||||
| 113 | |||||||||||
| 114 | # in Freenode tab | ||||||||||
| 115 | /set nick YourNickHere | ||||||||||
| 116 | /servers add irc.freenode.net -ident yournamehere -pass secretpasswordhere | ||||||||||
| 117 | /connect | ||||||||||
| 118 | |||||||||||
| 119 | # Don't forget to | ||||||||||
| 120 | /config save | ||||||||||
| 121 | |||||||||||
| 122 | =head2 How do I get notifications whenever someone uses the word perl in a channel that isn't on magnet or freenode#perl | ||||||||||
| 123 | |||||||||||
| 124 | /rules add input not(channel("#perl")) matches("perl"): highlight | ||||||||||
| 125 | |||||||||||
| 126 | Rules are network-specific so just don't do that on Magnet. | ||||||||||
| 127 | |||||||||||
| 128 | =head2 How do I set up a command to ban the hostmask for a given nick in the current channel for 24h | ||||||||||
| 129 | |||||||||||
| 130 | You'll have to read the hostmask of the user specifically, but then | ||||||||||
| 131 | |||||||||||
| 132 | /mode +b ident@host.name.here | ||||||||||
| 133 | /delay 86400 mode -b ident@host.name.here | ||||||||||
| 134 | |||||||||||
| 135 | Note the lack of C</> on the inner C<mode> to C<delay> | ||||||||||
| 136 | |||||||||||
| 137 | =head1 AUTHOR | ||||||||||
| 138 | |||||||||||
| 139 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||
| 142 | |||||||||||
| 143 | 4 | 0x55AA; | |||||||||