DBIx::C...opeGuard(3)

✨ DBIx::Class::Storage::TxnScopeGuard ✨

okay so real talk: this is a page from the User Contributed Perl Documentation (the perl v5.42.0 gang, dated 2025-01-22, mwah πŸ’‹) and it's about the little module called DBIx::Class::Storage::TxnScopeGuard. bestie. it's so good. let's go πŸ’…

🌸 NAME 🌸

DBIx::Class::Storage::TxnScopeGuard β€” scope-based transaction handling, i.e. the guard that handles your transactions for you so you literally cannot forget 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

sub foo {
  my ($self, $schema) = @_;

  my $guard = $schema->txn_scope_guard;

  # Multiple database operations here

  $guard->commit;
}

look at that. clean. iconic. no cap 🌈

πŸ’– DESCRIPTION πŸ’–

So it's an object that behaves, like, a lot like Scope::Guard β€” same whole vibe β€” but it's hardcoded to do the right thing with transactions in DBIx::Class. that's it, that's the energy. it was built for exactly this and it slays at exactly this πŸ’€

πŸŽ€ METHODS πŸŽ€

⭐ new

Creating an instance of this class will start a new transaction β€” and it does that by implicitly calling "txn_begin" in DBIx::Class::Storage. so like, just making the object begins the txn. main character behavior honestly.

It expects a DBIx::Class::Storage object as its only argument. one argument. that's the whole thing. 🧚

⭐ commit

Commit the transaction, and stop guarding the scope. this is you saying "we're done here, ship it" ✨

If this method is not called and this object goes out of scope (e.g. an exception is thrown) then the transaction is rolled back, via "txn_rollback" in DBIx::Class::Storage. no commit = rollback, automatically, no questions asked 😭 so yes, the safety net is real and it's giving responsible queen.

πŸ‘‘ SEE ALSO πŸ‘‘

  • "txn_scope_guard" in DBIx::Class::Schema. β€” the schema-side entry point, go look πŸ‘€
  • Scope::Guard by chocolateboy (inspiration for this module) β€” the original muse, we stan πŸ“

🌈 FURTHER QUESTIONS? 🌈

Check the list of additional DBIC resources. (yes, there's a whole list, go check it fr fr)

This module is free software copyright by the DBIx::Class (DBIC) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library. 🫢


and that's the whole page, bestie β€” written by the DBIC authors, from the perl v5.42.0 docs, dated 2025-01-22, and honestly? she ate. πŸ’…πŸ”₯ mwah.

πŸ“¦ where this page comes from