Perinci::Object(3pm)

πŸ“¦
version 0.311 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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. πŸ‘‘


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