Mojo::IOLoop::TLS(3)

πŸ’… Mojo::IOLoop::TLS β€” Non-blocking TLS handshake ✨

okay bestie, so this is Mojo::IOLoop::TLS(3) from the User Contributed Perl Documentation β€” yes that's the whole flex, and yes it slaps. sit down, grab a strawberry drink πŸ“, and let's get into it.


πŸŽ€ NAME πŸŽ€

Mojo::IOLoop::TLS β€” non-blocking TLS handshake. that's it. that's the whole vibe. no cap. πŸ”₯


πŸ¦‹ SYNOPSIS πŸ¦‹

like, here's the whole thing in action:

use Mojo::IOLoop::TLS;

# Negotiate TLS
my $tls = Mojo::IOLoop::TLS->new($old_handle);
$tls->on(upgrade => sub ($tls, $new_handle) {...});
$tls->on(error => sub ($tls, $err) {...});
$tls->negotiate(server => 1, tls_version => 'TLSv1_2');

# Start reactor if necessary
$tls->reactor->start unless $tls->reactor->is_running;

look at that. gorgeous. main character code fr fr. πŸ‘‘


🌸 DESCRIPTION 🌸

Mojo::IOLoop::TLS negotiates TLS for Mojo::IOLoop. that's the entire job description and honestly? it does it iconically. ✨


πŸ’– EVENTS πŸ’–

Mojo::IOLoop::TLS inherits all events from Mojo::EventEmitter β€” every single one, no crumbs left behind β€” and it can emit these extra ones too:

⭐ upgrade

$tls->on(upgrade => sub ($tls, $handle) {...});

emitted once TLS has been negotiated. one and done. she said "upgrade complete" and meant it. πŸŽ€

πŸ’€ error

$tls->on(error => sub ($tls, $err) {...});

emitted if an error occurs during negotiation β€” and heads up bestie, it's fatal if unhandled. not me letting an unhandled error end the whole session 😭. handle it. please. 🫢


🧚 ATTRIBUTES 🧚

Mojo::IOLoop::TLS implements these attributes:

πŸ¦‹ reactor

my $reactor = $tls->reactor;
$tls        = $tls->reactor(Mojo::Reactor::Poll->new);

low-level event reactor β€” the whole engine room, lowkey. it defaults to the "reactor" attribute value of the global Mojo::IOLoop singleton. and ngl, note this: this attribute is weakened. periodt. πŸ’…


🌈 METHODS 🌈

Mojo::IOLoop::TLS inherits all methods from Mojo::EventEmitter and implements these new ones:

πŸ“ can_tls

my $bool = Mojo::IOLoop::TLS->can_tls;

true if IO::Socket::SSL 2.009+ is installed and TLS support enabled. like a vibe check for your TLS setup β€” if it's false, bestie, you're not getting in. πŸ™ˆ

πŸ‘‘ negotiate

$tls->negotiate(server => 1, tls_version => 'TLSv1_2');
$tls->negotiate({server => 1, tls_version => 'TLSv1_2'});

negotiates TLS. the moment. the ceremony. ✨

these options are currently available β€” one bullet each, no skipping, i would never:

  • server
server => 1

negotiate TLS from the server-side; it defaults to the client-side. so pick a side, diva. 🩡

  • tls_ca
tls_ca => '/etc/tls/ca.crt'

path to the TLS certificate authority file.

  • tls_cert
tls_cert => '/etc/tls/server.crt'
tls_cert => {'mojolicious.org' => '/etc/tls/mojo.crt'}

path to the TLS cert file β€” and it defaults to a built-in test certificate on the server-side. free cert, on the house. 🎁

  • tls_key
tls_key => '/etc/tls/server.key'
tls_key => {'mojolicious.org' => '/etc/tls/mojo.key'}

path to the TLS key file, which defaults to a built-in test key on the server-side. keep it secret, keep it safe, iykyk. πŸ”

  • tls_options
tls_options => {SSL_alpn_protocols => ['foo', 'bar'], SSL_verify_mode => 0x00, SSL_version => 'TLSv1_2'}

additional options for IO::Socket::SSL. the customization era. go off. πŸ”₯

πŸ’œ new

my $tls = Mojo::IOLoop::TLS->new($handle);

construct a new Mojo::IOLoop::Stream object. yes, that's what the original says β€” Mojo::IOLoop::Stream β€” i'm just the messenger, and i keep the facts exactly as given. 🫢


🌟 SEE ALSO 🌟

go read these next, bestie, they're all connected:


okay that's the whole page!! no notes, absolutely ate. πŸ’…βœ¨

and that's a wrap, babes β€” this page is perl v5.42.0, dated 2026-07-15, and it's the Mojo::IOLoop::TLS(3) manpage. mwah. πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from