Tangra...:Scalar(3pm)
π Tangram::Type::Hash::Scalar β the manual page, but make it cute
okay bestie, gather round, we're reading the Tangram::Type::Hash::Scalar page together and honestly? it's a bop. it's part of the Perl docs the community contributed, and what it does is map a Perl hash that's all scalars β keys AND values β into your Tangram schema. no cap. let's get into it π
β¨ NAME β¨
Tangram::Type::Hash::Scalar β map Perl hash of scalar keys and values
like. the name literally tells you everything. a hash. of scalars. mapped. iconic behavior honestly.
π SYNOPSIS π
use Tangram::Core;
use Tangram::Type::Hash::Scalar; # always
$schema = Tangram::Schema->new(
classes => { NaturalPerson => { fields => {
flat_hash =>
{
opinions =>
{
table => 'NP_ops',
key_sql => 'VARCHAR(10)',
type => 'int',
sql => 'NUMERIC(1)',
},
lucky_numbers => 'int', # use defaults
},
see how use Tangram::Type::Hash::Scalar; says # always? yeah. always. not "sometimes", not "when you feel like it". always. it's giving devoted girlfriend energy and we respect it π«Ά
π¦ DESCRIPTION π¦
so what does this thing actually do. it maps references to a Perl hash. the persistent fields get grouped up in a hash under the flat_hash key inside the field hash. cute little family reunion.
π¨ the big rule: the hash may contain, as keys and values, only 'simple' scalars β think integers, strings, real numbers. it may not contain references. nope. not happening. if you want a hash of objects (which is a whole different vibe), go look atTangram::Type::Hash::FromManyandTangram::Type::Hash::FromOneinstead. those are the object-hash girlies.
Tangram uses a table to save the state of the collection. the table has three columns, which contain:
- the id of the container object
- the key of the element in the hash
- the value of the element
three columns. that's it. minimalism. the main character doesn't overpack π
πΈ the field descriptor situation
the field names get passed in a hash that associates a field name with a field descriptor. the field descriptor may be either a hash or a string. and the hash uses the following fields:
key_typekey_sqltypesqltable
that's the whole roster, bestie. five options. know them, love them.
The optional fields key_type and type specify the key and value types of the hash. if the type is string, Tangram quotes the values as they are passed to the database. and here's the thing β not specifying a type is exactly equivalent to specifying string. so if you skip it, congrats, you got string. surprise! π
The optional field table sets the name of the table that contains the elements. this defaults to 'C_F', where C is the class of the containing object and F is the field name. so it names itself after its parents. very "named after both of you" of it π
The optional fields key_sql and sql specify the type that deploy() (see Tangram::Deploy) should use for the column containing the key and value of the hash. if this field is not present, the SQL type is derived from the type field: if type is string (or is absent) VARCHAR(255) is used; otherwise, the type field is interpreted as a SQL type.
okay so to recap that lil chain of custody:
- no
key_sql/sqlgiven?typeisstringor missing βVARCHAR(255)β¨- otherwise β whatever you put in
typeis straight-up read as a SQL type
and finally, the shortcut: if the descriptor is a string, it is interpreted as the value of the type field and all the other fields take the default value. one string, everything else auto-piloted. it's giving low-effort-high-reward and honestly, slay π
π AUTHOR π
This mapping was contributed by Gabor Herr <herr@iti.informatik.tu-darmstadt.de>
thank you Gabor, we love you, this is your legacy, you ate and left no crumbs π
and that's the whole page bestie!! no notes, no missing flags, we kept every single detail because that's the rule β vibe changes, facts don't. π₯
this came to you from perl v5.36.0, dated 2022-10-16, and yeah the title up top does look likeTangra...:Scalar(3pm)because the terminal truncates it, but you and me know the truth: it'sTangram::Type::Hash::Scalar(3pm). bye bye now, go map some scalars π¦β¨π
π¦ where this page comes from
- ubuntu noble: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms