Perinci::Object(3pm)
π Perinci::Object π
okay bestie, listen. you know how Rinci is out here living its pure-data-structure life? well this is the object-oriented glow-up for all that metadata. it's Perinci::Object, a Perl module, and it's literally just tiny wrappers around your hashes so you can go $thing->method instead of $thing->{key}. no cap, it's so much nicer. π¦
β¨ VERSION β¨
this doc is describing version 0.311 of Perinci::Object, from the Perl distribution Perinci-Object, and it was released on 2020-01-02. iconic behavior honestly. π
π SYNOPSIS π
use Perinci::Object; # automatically exports risub(), rivar(), ripkg(),
# envres(), envresmulti(), envrestable(), riresmeta()
use Data::Dump; # for dd()
# OO interface to function metadata.
my $risub = risub {
v => 1.1,
summary => 'Calculate foo and bar',
"summary.alt.lang.id_ID" => 'Menghitung foo and bar',
args => { a1 => { schema => 'int*' }, a2 => { schema => 'str' } },
features => { pure=>1 },
};
dd $risub->type, # "function"
$risub->v, # 1.1
$risub->arg('a1'), # { schema=>'int*' }
$risub->arg('a3'), # undef
$risub->feature('pure'), # 1
$risub->feature('foo'), # undef
$risub->langprop('summary'), # 'Calculate foo and bar'
$risub->langprop({lang=>'id_ID'}, 'summary'), # 'Menghitung foo and bar'
# setting arg and property
$risub->arg('a3', 'array'); # will actually fail for 1.0 metadata
$risub->feature('foo', 2); # ditto
# OO interface to variable metadata
my $rivar = rivar { ... };
# OO interface to package metadata
my $ripkg = ripkg { ... };
# OO interface to enveloped result
my $envres = envres [200, "OK", [1, 2, 3]];
dd $envres->is_success, # 1
$envres->status, # 200
$envres->message, # "OK"
$envres->result, # [1, 2, 3]
$envres->meta; # undef
# setting status, message, result, extra
$envres->status(404);
$envres->message('Not found');
$envres->result(undef);
$envres->meta({errno=>-100});
# OO interface to function/method result metadata
my $riresmeta = riresmeta { ... };
# an example of using envresmulti()
sub myfunc {
...
my $envres = envresmulti();
# add result for each item
$envres->add_result(200, "OK", {item_id=>1, payload=>"a"});
$envres->add_result(202, "OK", {item_id=>2, note=>"blah", payload=>"b"});
$envres->add_result(404, "Not found", {item_id=>3});
...
# finally, return the result
return $envres->as_struct;
}
# an example of using envrestable()
sub myfunc {
...
my $envres = envrestable();
$envres->add_field('foo');
$envres->add_field('bar');
...
return $envres->as_struct;
}
πΈ DESCRIPTION πΈ
so. Rinci does all its work with pure data structures, which is very demure, very mindful, no objects required. but sometimes, bestie, you just want a cute little object-oriented interface (a wrapper, basically) around that data. this module provides exactly that. that's it. that's the whole vibe. π«Ά
π FUNCTIONS π
π rimeta $meta => OBJECT
exported by default. it's a shortcut for Perinci::Object::Metadata->new($meta).
π risub $meta => OBJECT
exported by default. it's a shortcut for Perinci::Object::Function->new($meta).
π rivar $meta => OBJECT
exported by default. it's a shortcut for Perinci::Object::Variable->new($meta).
π ripkg $meta => OBJECT
exported by default. it's a shortcut for Perinci::Object::Package->new($meta).
π envres $res => OBJECT
exported by default. it's a shortcut for Perinci::Object::EnvResult->new($res).
π envresmulti $res => OBJECT
exported by default. it's a shortcut for Perinci::Object::EnvResultMulti->new($res).
π envrestable $res => OBJECT
exported by default. it's a shortcut for Perinci::Object::EnvResultTable->new($res).
π riresmeta $resmeta => OBJECT
exported by default. it's a shortcut for Perinci::Object::ResMeta->new($res). π
π HOMEPAGE π
the project's homepage is living its best life at <https://metacpan.org/release/Perinci-Object>. go say hi. π
π¦ SOURCE π¦
the source repository is at <https://github.com/perlancar/perl-Perinci-Object>. give it a star, it's giving main character energy. β
π BUGS π
please, please report any bugs or feature requests on the bugtracker website at <https://github.com/perlancar/perl-Perinci-Object/issues>. don't suffer in silence bestie, we can fix it together. π
also, when you submit a bug or a request, please include a test-file or a patch to an existing test-file that illustrates the bug or the feature you want. like, show us the receipts. π
π₯ SEE ALSO π₯
Rinciβ the whole reason any of this exists, fr fr.
πΈ AUTHOR πΈ
perlancar <perlancar@cpan.org> β the icon, the legend. π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2021, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org.
it's free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay. β¨
and that's the whole page, bestie! π«Ά this one came out as perl v5.36.0, dated 2022-10-13. now go wrap some hashes in objects, you got this. periodt. π
π¦ where this page comes from
- ubuntu noble: libperinci-object-perl 0.311-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libperinci-object-perl 0.311-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libperinci-object-perl 0.311-2 Β· 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