Rex::Transaction(3pm)
π Rex::Transaction π
okay bestie, so likeβ¦ this is Rex::Transaction, part of the User Contributed Perl Documentation. yes it's a Perl module manual page (a 3pm one, iykyk) and yes it's about transactions. stay with me. π«Ά
β¨ NAME β¨
Rex::Transaction β Transaction support. that's it, that's the name, periodt. π
π DESCRIPTION π
so with this module you can define transactions and rollback scenarios on failure. that's the whole vibe: you do a bunch of stuff, and if something goes wrong mid-way, Rex can undo it. main character energy fr fr. π₯
β SYNOPSIS β
here's the whole thing, exactly as it goes down:
use Rex::Transaction;
task 'do-something', 'server01', sub {
transaction {
on_rollback {
rmdir '/tmp/mydata';
};
mkdir '/tmp/mydata';
upload 'files/myapp.tar.gz', '/tmp/mydata';
run 'tar xzf myapp.tar.gz -C /tmp/mydata';
if ( $? != 0 ) { die('Error extracting myapp.tar.gz'); }
};
};
like. look at that. clean. πβ¨
πΈ EXPORTED FUNCTIONS πΈ
these are the two lil guys this module hands you. both iconic, both necessary.
π¦ transaction($codeRef)
Start a transaction for $codeRef. If $codeRef dies, Rex will run the on_rollback code to roll back the transaction. that's the deal, no cap. π
(if you wanna hop straight to that section on metacpan, it's on_rollback β https://metacpan.org/pod/Rex::Transaction#on_rollback.)
task 'deploy', group => 'frontend', sub {
on_rollback {
rmdir '...';
};
deploy 'myapp.tar.gz';
};
task 'restart_server', group => 'frontend', sub {
service apache2 => 'restart';
};
task 'all', group => 'frontend', sub {
transaction {
do_task [qw/deploy restart_server/];
};
};
see how deploy and restart_server both get swept up into one transaction? so if the restart flops, the deploy gets rolled back too. chef's kiss. π
π on_rollback($codeRef)
This will execute $codeRef if a step in the transaction fails. (here's the link if you need it: https://metacpan.org/pod/Rex::Transaction#transaction.) it's your little safety net, your plan B, your "okay we're fixing this" moment. πβ¨
ok real talk bestie β on_rollback only fires when a step in the transaction fails. so put your cleanup code in there and make it count. π
π one (1) tiny detail before you go π
nothing else here to warn you about β the page really is this short. go forth and transact. π
and that's a wrap on the Rex::Transaction(3pm) page, bestie π it came to you from the User Contributed Perl Documentation, running on perl v5.40.1, dated 2025-10-03. slay, bye, see you in the next manpage. ππ¦π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms