| 1 | package App::Sysadmin::Log::Simple::UDP; | ||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 5 | ▶ | use IO::Socket::INET; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 5 | ▶ | use autodie qw(:socket); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | # ABSTRACT: a UDP-logger for App::Sysadmin::Log::Simple | ||||||||||||
| 9 | 5 | our $VERSION = '0.009'; # VERSION | |||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||
| 13 | 4 | my $class = shift; | |||||||||||
| 14 | 4 | my %opts = @_; | |||||||||||
| 15 | 4 | my $app = $opts{app}; | |||||||||||
| 16 | |||||||||||||
| 17 | 4 | ▶ | $app->{udp}->{host} ||= 'localhost'; | ||||||||||
|
Condition50%1/2
$app->{"udp"}{"host"} ||= "localhost"
MC/DC0%0/1
$app->{"udp"}{"host"} ||= "localhost"
$app->{"udp"}{"host"}
Truth table50%1/2
A
A= $app->{"udp"}{"host"}
| |||||||||||||
| 18 | 4 | ▶ | $app->{udp}->{port} ||= 9002; | ||||||||||
|
Condition50%1/2
$app->{"udp"}{"port"} ||= 9002
MC/DC0%0/1
$app->{"udp"}{"port"} ||= 9002
$app->{"udp"}{"port"}
Truth table50%1/2
A
A= $app->{"udp"}{"port"}
| |||||||||||||
| 19 | |||||||||||||
| 20 | return bless { | ||||||||||||
| 21 | do_udp => $app->{do_udp}, | ||||||||||||
| 22 | udp => $app->{udp}, | ||||||||||||
| 23 | user => $app->{user}, | ||||||||||||
| 24 | 4 | }, $class; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub log { | ||||||||||
|
Subroutine
log: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||
| 30 | 0 | my $logentry = shift; | |||||||||||
| 31 | |||||||||||||
| 32 | 0 | ▶ | return unless $self->{do_udp}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | |||||||||||||
| 34 | my $sock = IO::Socket::INET->new( | ||||||||||||
| 35 | Proto => 'udp', | ||||||||||||
| 36 | PeerAddr => $self->{udp}->{host}, | ||||||||||||
| 37 | PeerPort => $self->{udp}->{port}, | ||||||||||||
| 38 | 0 | ); | |||||||||||
| 39 | 0 | ▶ | carp "Couldn't get a socket: $!" unless $sock; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | if ($self->{udp}->{irc}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | my %irc = ( | |||||||||||
| 43 | normal => "\x0F", | ||||||||||||
| 44 | bold => "\x02", | ||||||||||||
| 45 | underline => "\x1F", | ||||||||||||
| 46 | white => "\x0300", | ||||||||||||
| 47 | black => "\x0301", | ||||||||||||
| 48 | blue => "\x0302", | ||||||||||||
| 49 | green => "\x0303", | ||||||||||||
| 50 | lightred => "\x0304", | ||||||||||||
| 51 | red => "\x0305", | ||||||||||||
| 52 | purple => "\x0306", | ||||||||||||
| 53 | orange => "\x0307", | ||||||||||||
| 54 | yellow => "\x0308", | ||||||||||||
| 55 | lightgreen => "\x0309", | ||||||||||||
| 56 | cyan => "\x0310", | ||||||||||||
| 57 | lightcyan => "\x0311", | ||||||||||||
| 58 | lightblue => "\x0312", | ||||||||||||
| 59 | lightpurple => "\x0313", | ||||||||||||
| 60 | grey => "\x0314", | ||||||||||||
| 61 | lightgrey => "\x0315", | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | |||||||||||||
| 64 | my $ircline = $irc{bold} . $irc{green} . '(LOG)' . $irc{normal} | ||||||||||||
| 65 | . ' ' . $irc{underline} . $irc{lightblue} . $self->{user} . $irc{normal} | ||||||||||||
| 66 | 0 | . ': ' . $logentry . "\r\n"; | |||||||||||
| 67 | 0 | print $sock $ircline; | |||||||||||
| 68 | } | ||||||||||||
| 69 | else { | ||||||||||||
| 70 | 0 | print $sock "(LOG) $self->{user}: $logentry\r\n"; | |||||||||||
| 71 | } | ||||||||||||
| 72 | 0 | $sock->shutdown(2); | |||||||||||
| 73 | |||||||||||||
| 74 | 0 | return "Logged to $self->{udp}->{host}:$self->{udp}->{port}"; | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 5 | 1; | |||||||||||
| 78 | |||||||||||||
| 79 | __END__ | ||||||||||||