# File: FuncSed.pm # # Purpose: Registers the sed Function # SPDX-FileCopyrightText: 2020-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Plugin::FuncSed; use parent 'PBot::Plugin::Base'; use PBot::Imports; sub initialize($self, %conf) { $self->{pbot}->{functions}->register( 'sed', { desc => 'a sed-like stream editor', usage => 'sed s///[Pig]; P preserve case; i ignore case; g replace all', subref => sub { $self->func_sed(@_) } } ); } sub unload($self) { $self->{pbot}->{functions}->unregister('sed'); } # near-verbatim insertion of krok's `sed` factoid no warnings; sub func_sed($self, @rest) { my $text = "@rest"; my $result = eval { if ($text =~ /^s(.)(.*?)(?//[Pig]; P preserve case; i ignore case; g replace all'; } }; if (my $e = $@) { $e =~ s/ at .*$//; return "sed: syntax error: $e"; } return $result; } use warnings; 1;