| 1 | package Bot::BasicBot::Pluggable::Module::MetaSyntactic; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Bot::BasicBot::Pluggable::Module::MetaSyntactic::VERSION = '1.004'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Bot::BasicBot::Pluggable::Module; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Acme::MetaSyntactic (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Text::Wrap; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our @ISA = qw(Bot::BasicBot::Pluggable::Module); | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my $META = Acme::MetaSyntactic->new() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | or carp "fatal: Can't create new Acme::MetaSyntactic object"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | $self->{meta} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | limit => 100, | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | wrap => 256, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | $Text::Wrap::columns = $self->{meta}{wrap}; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 29 | ▶ | sub told { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
told: called CC=35 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 29 | my ( $self, $mess ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 29 | my $bot = $self->bot(); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # we must be directly addressed | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | if !( ( defined $mess->{address} | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | && $mess->{address} eq $bot->nick() | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 29 | ▶ | || $mess->{channel} eq 'msg' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick
MC/DC33%1/3
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
defined $mess->{"address"}
$mess->{"address"} eq $bot->nick
$mess->{"channel"} eq "msg"
Truth table60%3/5
A and B or C
A= defined $mess->{"address"}B= $mess->{"address"} eq $bot->nickC= $mess->{"channel"} eq "msg"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # ignore people we ignore | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 27 | ▶ | return if $bot->ignore_nick( $mess->{who} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # only answer to our command (which can be our name too) | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 27 | ▶ | my $src = $bot->nick() eq 'meta' ? 'raw_body' : 'body'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 27 | ▶ | return if $mess->{$src} !~ /^\s*meta(.*)/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # ignore the noise | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | ( my $command = "$1" ) =~ s/^\W*//; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # pick up the commands | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | ( $command, my @args ) = split /\s+/, $command; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | ▶ | return if !$command || !length $command; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$command and length $command
MC/DC50%1/2
$command and length $command
$command
length $command
Truth table66%2/3
A and B
A= $commandB= length $command
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # it's a theme | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 24 | ▶ | if ( $command =~ /^[-\w\/]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 20 | my ( $theme, $category ) = split m'/', $command, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 20 | ▶ | $self->{meta}{theme}{$command} //= _load_theme($theme, $category); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"meta"}{"theme"}{$command} //= _load_theme($theme, $category)
MC/DC0%0/2
$self->{"meta"}{"theme"}{$command} //= _load_theme($theme, $category)
$self->{"meta"}{"theme"}{$command}
_load_theme($theme, $category)
Truth table66%2/3
A //= B
A= $self->{"meta"}{"theme"}{$command}B= _load_theme($theme, $category)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 20 | ▶ | return "No such theme: $theme" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | if !$META->has_theme($theme); | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 19 | ▶ | if ( $category && $self->{meta}{theme}{$command} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") and not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList")
MC/DC66%2/3
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") and not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
$category
$self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList")
not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
Truth table75%3/4
A and B and not(C)
A= $categoryB= $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList")C= not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ->isa('Acme::MetaSyntactic::MultiList') | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | && !grep { $_ eq $category } | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | $self->{meta}{theme}{$command}->categories ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | delete $self->{meta}{theme}{$command}; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | return "No such theme/category: $theme/$category"; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # compute the list of items | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 18 | my ( $num, $re ); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 18 | for my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 22 | ▶ | if ( $arg =~ /^[0-9]+$/ ) { $num //= $arg; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$num //= $arg
MC/DC0%0/2
$num //= $arg
$num
$arg
Truth table33%1/3
A //= B
A= $numB= $arg
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | elsif ( $arg =~ m{^/([^\/]*)/$} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | $re = eval {qr/$1/} | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | or do { ( my $err = $@ ) =~ s/ at .*//s; return $err; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | else {return} # can't parse this argument | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # enforce the limit if explicitely asked for more | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | ▶ | $num //= 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$num //= 1
MC/DC100%1/1
$num //= 1
$num
Truth table100%2/2
A
A= $num
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | ▶ | $num = $self->{meta}{limit} if $num > $self->{meta}{limit}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | my $meta = $self->{meta}{theme}{$command}; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | my @items = $meta->name( $re ? 0 : $num ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | ▶ | if ($re) { # NOTE: the extra loop is never run if $num == 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | @items = grep /$re/, @items; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | ▶ | splice @items, $num if $num && @items > $num; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$num and @items > $num
MC/DC100%2/2
$num and @items > $num
$num
@items > $num
Truth table100%3/3
A and B
A= $numB= @items > $num
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | ▶ | push @items, grep /$re/, $meta->name(0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@items and @items < $num
MC/DC100%2/2
@items and @items < $num
@items
@items < $num
Truth table100%3/3
A and B
A= @itemsB= @items < $num
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | while @items && @items < $num; | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | splice @items, $self->{meta}{limit} # enforce the limit | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 16 | ▶ | if @items > $self->{meta}{limit}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | return join ' ', @items; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # it's a command | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | elsif ( $command eq 'themes?' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my @themes = $META->themes(); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | return join ' ', scalar @themes, 'themes available:', @themes; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | elsif ( $command eq 'categories?' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | return if !@args; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | my $theme = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | $self->{meta}{theme}{$theme} //= _load_theme($theme); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"meta"}{"theme"}{$theme} //= _load_theme($theme)
MC/DC0%0/2
$self->{"meta"}{"theme"}{$theme} //= _load_theme($theme)
$self->{"meta"}{"theme"}{$theme}
_load_theme($theme)
Truth table66%2/3
A //= B
A= $self->{"meta"}{"theme"}{$theme}B= _load_theme($theme)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | ▶ | return "No such theme: $theme" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | if !$META->has_theme($theme); | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | return "Theme $theme does not have any categories" | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | if !$self->{meta}{theme}{$theme} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ->isa('Acme::MetaSyntactic::MultiList'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | return join ' ', "Categories for $theme:", | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | sort $self->{meta}{theme}{$theme}->categories; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | sub _load_theme { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_theme: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | my ($theme, $category) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | my $module = "Acme::MetaSyntactic::$theme"; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | return eval "require $module" || $META->has_theme($theme) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
eval "require $module" or $META->has_theme($theme)
MC/DC100%2/2
eval "require $module" or $META->has_theme($theme)
eval "require $module"
$META->has_theme($theme)
Truth table100%3/3
A or B
A= eval "require $module"B= $META->has_theme($theme)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ? $module->new( ( category => $category ) x !!$category ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | sub help {'meta theme [count]'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # ABSTRACT: IRC frontend to Acme::MetaSyntactic | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||