App-SpreadRevolutionaryDate

 view release on metacpan or  search on metacpan

lib/App/SpreadRevolutionaryDate/Target.pm  view on Meta::CPAN

#
# This software is Copyright (c) 2019-2026 by Gérald Sédrati.
#
# This is free software, licensed under:
#
#   The GNU General Public License, Version 3, June 2007
#
use 5.014;
use utf8;
package App::SpreadRevolutionaryDate::Target;
$App::SpreadRevolutionaryDate::Target::VERSION = '0.54';
# ABSTRACT: Role providing interface for targets of L<App::SpreadRevolutionaryDate>.

use MooseX::Role::Parameterized;
use LWP::Protocol::https;

use Locale::TextDomain 'App-SpreadRevolutionaryDate';
use namespace::autoclean;

parameter worker => (
  isa     => 'Str',
  default => 'Any',
);

role {
  my $p = shift;

  has obj => (
    is => 'ro',
    isa => $p->worker,
    required => 1,
  );

  requires 'spread';
};

sub _split_msg {
  my ($self, $text, $max_len) = @_;
  my @msgs;
  while ($text) {
    if (length $text <= $max_len) {
      push @msgs, $text;
      last;
    }
    my $prefix = substr $text, 0, $max_len;
    my $loc = rindex $prefix, ' ';

    if ($loc == -1) {
      die "We found a word which is longer than $max_len\n";
    }
    my $str = substr $text, 0, $loc, '';
    push @msgs, $str;
    substr $text, 0, 1, '';
  }
  return @msgs;
}


# A module must return a true value. Traditionally, a module returns 1.
# But this module is a revolutionary one, so it discards all old traditions.
# Idea borrowed from Jean Forget's DateTime::Calendar::FrenchRevolutionary.
"Quand le gouvernement viole les droits du peuple,
l'insurrection est pour le peuple le plus sacré
et le plus indispensable des devoirs";

__END__

=pod

=encoding UTF-8

=head1 NAME

App::SpreadRevolutionaryDate::Target - Role providing interface for targets of L<App::SpreadRevolutionaryDate>.

=head1 VERSION

version 0.54

=head1 DESCRIPTION

This role defines the interface for any target which L<App::SpreadRevolutionaryDate> should spread the revolutionary date to.

Any consuming class can parameterize this role (through L<MooseX::Role::Parameterized>) with a C<worker> type set to the effective Perl module implementing any protocol needed by this target (eg. L<App::SpreadRevolutionaryDate::BlueskyLite>, L<Twitte...

Any class consuming this role is required to implement a C<spread> method, which is called with three parameters: C<msg>, the message as a string to be spread; C<test>, an optional boolean which informs this method to actually spread the message if t...

If the target needs authentication, it can be carried out in the constructor (with L<Moose> C<BUILDARGS> or C<BUILD>) or in the implementation of the C<spread> method, obviously before actually spreading the message.

There is a L<Bluesky|https://metacpan.org/pod/Bluesky> Perl module on CPAN that would have been the best choice of C<worker> for L<Bluesky|https://bsky.app/>. But it needs at least Perl v5.40.0, which is a requirement that most Perl installations doe...

=head1 SEE ALSO

=over

=item L<spread-revolutionary-date>

=item L<App::SpreadRevolutionaryDate>

=item L<App::SpreadRevolutionaryDate::Config>

=item L<App::SpreadRevolutionaryDate::BlueskyLite>

=item L<App::SpreadRevolutionaryDate::Target::Bluesky>

=item L<App::SpreadRevolutionaryDate::Target::Twitter>

=item L<App::SpreadRevolutionaryDate::Target::Mastodon>

=item L<App::SpreadRevolutionaryDate::Target::Freenode>

=item L<App::SpreadRevolutionaryDate::Target::Freenode::Bot>

=item L<App::SpreadRevolutionaryDate::Target::Liberachat>

=item L<App::SpreadRevolutionaryDate::Target::Liberachat::Bot>

=item L<App::SpreadRevolutionaryDate::MsgMaker>

=item L<App::SpreadRevolutionaryDate::MsgMaker::RevolutionaryDate>



( run in 0.484 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )