Storm::Policy(3)

πŸ“¦
version 0.240 Β· 2 versions
, in fedora 43

πŸ’– Storm::Policy(3) πŸ’–

okay bestie, you found it β€” this is Storm::Policy, a page from the User Contributed Perl Documentation, and it's literally the manual for telling Storm how your types get shoved into and yanked back out of a database. slay.


✨ NAME ✨

Storm::Policy β€” defines how types are stored/retrieved from the database. that's it, that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

package MyPolicy;
use Storm::Policy;
use Moose::Util::TypeConstraints;
use DateTime::Format::SQLite;

class_type 'DateTime',
    { class => 'DateTime' };

define 'DateTime', 'DATETIME';

transform 'DateTime',
    inflate { DateTime::Format::SQLite->parse_datetime( $_ ) },
    deflate { DateTime::Format::SQLite->format_datetime( $_ ) };

# and then later

$storm = Storm->new( source => ... , policy => 'MyPolicy' );

look at her go πŸ¦‹ she's just a little policy package and she's doing SO much.


πŸ’œ DESCRIPTION πŸ’œ

so, the policy is the thing that decides how data is stored in the database. Storm::Policy is basically sugar β€” sweet, sweet syntactic sugar πŸ“ β€” that lets you declare the data type for the DBMS and transform values on inflation/deflation. two jobs. one icon. no cap.


πŸŽ€ SUGAR πŸŽ€

define $type, $dbms_type

define declares the data type to be used by the DBMS (that's Database Management Software, iykyk) when storing values of the given $type. so you're like "hey bestie, this $type? it lives as $dbms_type in the database." periodt. πŸ‘‘

transform inflate \&func, deflate \&func

transform is where you declare how values of the given type will be serialized when stored to the database. and here's the fun part β€” using transformations can allow you to store complex objects. yes really. the whole glow-up. ✨

  • the deflate function is used when storing a value to the database. $_ is the value to be deflated, and the return value is what will be saved to the database.
  • the inflate function is used when retrieving the value from the database. $_ is the value to be inflated, and the return value is the value Storm will use.
lowkey the cleanest in/out pipeline ever. deflate on the way in, inflate on the way out. no notes. πŸ’–

🫢 AUTHOR 🫢

Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>

modified from code in Dave Rolsky's Fey::ORM module. shoutout to the ancestors, fr fr 🌈


Copyright (c) 2010 Jeffrey Ray Hallock. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

and that's the whole page, bestie πŸ’… go forth and define your types.

this has been Storm::Policy(3), shipped as part of perl v5.42.0, dated 2025-07-25 β€” mwah, take care of her πŸŽ€βœ¨

πŸ“¦ where this page comes from