App-SpreadRevolutionaryDate
view release on metacpan or search on metacpan
lib/App/SpreadRevolutionaryDate/Target/Bluesky.pm view on Meta::CPAN
#
# This file is part of App-SpreadRevolutionaryDate
#
# 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::Bluesky;
$App::SpreadRevolutionaryDate::Target::Bluesky::VERSION = '0.54';
# ABSTRACT: Target class for L<App::SpreadRevolutionaryDate> to handle spreading on Bluesky.
use Moose;
with 'App::SpreadRevolutionaryDate::Target'
=> {worker => 'App::SpreadRevolutionaryDate::BlueskyLite'};
use App::SpreadRevolutionaryDate::BlueskyLite;
use Encode qw(encode decode is_utf8);
use Locale::TextDomain 'App-SpreadRevolutionaryDate';
use namespace::autoclean;
has 'identifier' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'password' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'max_lenght' => (
is => 'ro',
isa => 'Int',
required => 1,
default => 250,
);
around BUILDARGS => sub {
my ($orig, $class) = @_;
my $args = $class->$orig(@_);
$args->{obj} = App::SpreadRevolutionaryDate::BlueskyLite->new(
identifier => $args->{identifier},
password => $args->{password},
);
return $args;
};
sub spread {
my ($self, $msg, $test, $img) = @_;
$test //= 0;
# Multiline message
$msg =~ s/\\n/\n/g;
if ($test) {
$msg = __("Spread on Bluesky: ") . $msg;
if ($img) {
$msg .= " with image path: " . $img->{path} . " , alt: " . $img->{alt};
}
use open qw(:std :encoding(UTF-8));
use IO::Handle;
my $io = IO::Handle->new;
$io->fdopen(fileno(STDOUT), "w");
my @msgs = $self->_split_msg($msg, $self->max_lenght);
for (my $i = 0; $i < scalar @msgs; $i++) {
my $msg = "Message " . ($i+1) . ": " . $msgs[$i];
$msg = encode('UTF-8', $msg) if is_utf8($msg);
$io->say($msg);
}
( run in 2.049 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )