UR::Ob...operty(3pm)

πŸ“¦
version 0.470 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

✨ NAME ✨

UR::Object::Property β€” bestie, this is the class that represents metadata about a class property. it's the little info-card behind every property your class has πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's how you actually touch one:

my $prop = UR::Object::Property->get(class_name => 'Some::Class', property_name => 'foo');

my $class_meta = Some::Class->__meta__;
my $prop2 = $class_meta->property_meta_for_name('foo');

# Print out the meta-property name and its value of $prop2
print map { " $_ : ".$prop2->$_ }
      qw(class_name property_name data_type default_value);

like, grab the meta, ask it about a property, print the juicy bits. slay πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so, instances of this class represent properties of classes. every single item you mention in the has or id_by section of a class definition? yeah, each one becomes a Property object. no cap. 🫢


🌸 INHERITANCE 🌸

UR::Object::Property is a subclass of UR::Object. it's giving legacy, it's giving lineage, it's giving "my parent is iconic" ✨


πŸ’œ PROPERTY TYPES πŸ’œ

okay so take this class definition, look at it, absorb it:

class Some::Class {
    has => [
        other_id => { is => 'Text' },
        other    => { is => 'Some::Other', id_by => 'foo_id' },
        bar      => { via => 'other', to => 'bar' },
        foos     => { is => 'Some::Foo', reverse_as => 'some', is_many => 1 },
        uc_other_id => { calculate_from => 'other_id',
                         calculate_perl => 'uc($other_id)' },
    ],
};

Properties generally fall in to one of these categories, bestie:

  • regular property β€” a regular property of a class holds a single scalar. in this case, other_id is a regular property. one value, one vibe πŸ’…
  • object accessor β€” an object accessor property returns objects of some class. the properties of this class must link in some way with all the ID properties of the remote class (the is declaration). other is an object accessor property. this is how one-to-one relationships are implemented πŸ”₯
  • via property β€” when a class has some object accessor property, and it's helpful for an object to assume the value of the remote class's properties, you can set up a via property. in the example above, an object of this class gets the value of its bar property via the other object it's linked to, from that object's bar property. it's giving "borrowed but make it fashion" ✨
  • reverse as or is many property β€” this is how one-to-many relationships are implemented. in this case, the Some::Foo class must have an object accessor property called some, and the foos property will return a list of all the Some::Foo objects where their some property would have returned that object. one object, many friends, periodt πŸŽ€
  • calculated property β€” a calculated property doesn't store its data directly in the object, but when its accessor is called, the calculation code is executed. math but make it meta 🧚

πŸ’– PROPERTIES πŸ’–

each property has a method of the same name. iykyk.

πŸŽ€ Direct Properties πŸŽ€

  • class_name => Text β€” the name of the class this Property is attached to πŸ‘‘
  • property_name => Text β€” the name of the property. the pair of class_name and property name are the ID properties of UR::Object::Property. literally the dynamic duo fr fr πŸ’«
  • column_name => Text β€” if the class is backed by a database table, then the column this property's data comes from is stored here πŸ—„οΈ
  • data_type => Text β€” the type of data stored in this property. corresponds to the is part of a class's property definition.
  • data_length => Number β€” the maximum size of data stored in this property πŸ“
  • default_value β€” for is_optional properties, the default value given when an object is created and this property is not assigned a value. the fallback, the backup dancer, the understudy πŸ’…
  • valid_values => ARRAY β€” a listref of enumerated values this property may be set to βœ…
  • doc => Text β€” a place for documentation about this property πŸ“
  • is_id => Boolean β€” indicates whether this is an ID property of the class
  • is_optional => Boolean β€” indicates whether this is property may have the value undef when the object is created
  • is_transient => Boolean β€” indicates whether this is property is transient?
  • is_constant => Boolean β€” indicates whether this property can be changed after the object is created πŸ”’
  • is_mutable => Boolean β€” indicates this property can be changed via its accessor. properties cannot be both constant and mutable. pick a lane bestie 😭
  • is_volatile => Boolean β€” indicates this property can be changed by a mechanism other than its normal accessor method. signals are not emitted even when it does change via its normal accessor method. sneaky little thing πŸ™ˆ
  • is_classwide => Boolean β€” indicates this property's storage is shared among all instances of the class. when the value is changed for one instance, that change is effective for all instances. group chat rules: one message, everyone sees it πŸ’€
  • is_delegated => Boolean β€” indicates that the value for this property is not stored in the object directly, but is delegated to another object or class.
  • is_calculated => Boolean β€” indicates that the value for this property is not a part of the object'd data directly, but is calculated in some way.
  • is_transactional => Boolean β€” indicates the changes to the value of this property is tracked by a Context's transaction and can be rolled back if necessary. undo button energy πŸ”„
  • is_abstract => Boolean β€” indicates this property exists in a base class, but must be overridden in a derived class.
  • is_concrete => Boolean β€” antonym for is_abstract. properties cannot be both is_abstract and is_concrete. not both, bestie, choose your fighter πŸ₯Š
  • is_final => Boolean β€” indicates this property cannot be overridden in a derived class. it's giving "no takebacks" 🚫
  • is_deprecated => Boolean β€” indicates this property's use is deprecated. it has no effect in the use of the property in any way, but is useful in documentation. the caution tape is decorative but it IS there ⚠️
  • implied_by => Text β€” if this property is created as a result of another property's existence, implied_by is the name of that other property. this can happen in the case where an object accessor property is defined
has => [
    foo => { is => 'Some::Other', id_by => 'foo_id' },
],

here, the foo property requires another property called foo_id, which is not explicitly declared. in this case, the Property named foo_id will have its implied_by set to foo. surprise property, but in a cute way 🎁

  • id_by => ARRAY β€” in the case of an object accessor property, this is the list of properties in this class that link to the ID properties in the remote class.
  • reverse_as => Text β€” defines the linking property name in the remote class in the case of an is_many relationship
  • via => Text β€” for a via-type property, indicates which object accessor to go through. the middleman, the connector, the group chat admin 🧚
  • to => Text β€” for a via-type property, indicates the property name in the remote class to get its value from. the default value is the same as property_name.
  • where => ARRAY β€” supplies additional filters for indirect properties. for example:
foos => { is => 'Some::Foo', reverse_as => 'some', is_many => 1 },
blue_foos => { via => 'foos', where => [ color => 'blue' ] },

would create a property blue_foos which returns only the related Some::Foo objects that have 'blue' color. filtering? we love to see it πŸ’™

  • calculate_from => ARRAY β€” for calculated properties, this is a list of other property names the calculation is based on
  • calculate_perl => Text β€” for calculated properties, a string containing Perl code. any properties mentioned in calculate_from will exist in the code's scope at run time as scalars of the same name. code-as-string, it's giving chaotic but it works ✨
  • class_meta => UR::Object::Type β€” returns the class metaobject of the class this property belongs to πŸ‘‘

πŸ”₯ METHODS πŸ”₯

  • via_property_meta β€” for via/to delegated properties, return the property meta in the same class this property delegates through
  • to_property_meta β€” for via/to delegated properties, return the property meta on the foreign class that this property delegates to

🌈 SEE ALSO 🌈

UR::Object::Type, UR::Object::Type::Initializer, UR::Object β€” go read those too bestie, they're all in the same friend group 🫢


okay that's the whole thing, you ate it, no crumbs. this page came from perl v5.32.1 and it's dated 2022-01-17, so it's a lil vintage but it still slays πŸ’–βœ¨

πŸ“¦ where this page comes from