Storm::Model(3)

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

πŸ’– Storm::Model(3) β€” aka Storm::Object

ok so bestie, you're looking at the Storm::Model(3) page from the User Contributed Perl Documentation section, and honestly? it's giving object-relational realness. buckle up πŸŽ€


✨ NAME ✨

Storm::Object β€” build objects to use with Storm. that's it, that's the whole vibe πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

no cap, this is the whole shape of it:

package Foo;
use Storm::Object;  # provides Moose sugar

has 'id' => (
    isa => 'Int',
    traits => [qw( PrimaryKey AutoIncrement )],
);

has 'label' => (
    isa => 'Str',
);

has 'bar' => (
    isa => 'Bar',
    weak_ref => 1,
)

package Bar;

has 'id' => (
    isa => 'Int',
    traits => [qw( PrimaryKey AutoIncrement )],
);

has_many 'foos' => (
    foreign_class => 'Foo',
    match_on => 'bar',
    handles => {
        foos => 'iter',
    }
);

has_many 'bazzes' => (
    foreign_class => 'Baz',
    junction_table => 'BazBars',
    local_match => 'bar',
    foreign_match => 'baz',
    handles => {
        bazzes => 'iter',
        add_baz => 'add',
        remove_baz => 'remove',
    }
);

package Baz;

has 'id' => (
    isa => 'Int',
    traits => [qw( PrimaryKey AutoIncrement )],
);

has_many 'bars' => (
    foreign_class => 'Foo',
    junction_table => 'BazBars',
    local_match => 'bar',
    foreign_match => 'baz',
    handles => {
        bars => 'iter',
        add_bar => 'add',
        remove_bar => 'remove',
    }
);

like… it's a whole little polycule of classes and they all know each other 🫢 copy it exactly, the commas and semicolons are load-bearing, iykyk.


🌸 DESCRIPTION 🌸

okay so Storm::Object is an extension of the Moose object system. its whole purpose, its main character moment, is to apply the meta-roles Storm needs to be able to introspect your objects β€” and also to hand you some sugar for declaring relationships between Storm-enabled objects. sweet, right? πŸ“


πŸ‘‘ ROLES/META-ROLES πŸ‘‘

these are the roles doing the behind-the-scenes work:

  • Storm::Role::Object β€” this role is applied to the base class. the foundation, the blueprint, the moment.
  • Storm::Role::Object::Meta::Attribute β€” this role is applied to the attribute meta-class. yes, the attribute one.
  • Storm::Role::Object::Meta::Class β€” and this role is applied to the class meta-class. periodt.

🧚 SUGAR 🧚

has_many $name => %options

this is the big one, the icon, the queen bee πŸ‘‘ it takes a $name and a big old pile of %options:

  • foreign_class => $class β€” set the foreign_class option to the other class in the relationship. the plus-one, if you will πŸ’œ
  • match_on => $attribute_name β€” use this one when you're defining a one-to-many relationship. it's the name of the attribute in the foreign class that defines the relationship.
  • junction_table => $table β€” use this one when you're defining a many-to-many relationship. it's the database table that defines the relationships.
  • local_match => $table β€” again for the many-to-many girlies. this is the column in the junction_table that identifies the __PACKAGE__ object in the relationship.
  • foreign_match => $table β€” and last but not least, also for many-to-many. this is the column in the junction_table that identifies the foreign object in the relationship. 🌈
note bestie: local_match and foreign_match are both documented as taking $table in the original, so that's what we're keeping. no editing the queen's typo history πŸ’€

πŸ’– AUTHOR πŸ’–

Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com> β€” shoutout, the actual author, no notes πŸ™Œ


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.

so yeah, free software, same terms as Perl itself, slay πŸ’…


okay bestie that's the whole page πŸŽ€ this was Storm::Model(3) from perl v5.42.0, dated 2025-07-25 β€” go forth and build your objects, you've got this, no cap βœ¨πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from