| 1 |
NAME |
| 2 |
Perinci::Object - Object-oriented interface for Rinci metadata |
| 3 |
|
| 4 |
VERSION |
| 5 |
This document describes version 0.311 of Perinci::Object (from Perl |
| 6 |
distribution Perinci-Object), released on 2020-01-02. |
| 7 |
|
| 8 |
SYNOPSIS |
| 9 |
use Perinci::Object; # automatically exports risub(), rivar(), ripkg(), |
| 10 |
# envres(), envresmulti(), envrestable(), riresmeta() |
| 11 |
use Data::Dump; # for dd() |
| 12 |
|
| 13 |
# OO interface to function metadata. |
| 14 |
|
| 15 |
my $risub = risub { |
| 16 |
v => 1.1, |
| 17 |
summary => 'Calculate foo and bar', |
| 18 |
"summary.alt.lang.id_ID" => 'Menghitung foo dan bar', |
| 19 |
args => { a1 => { schema => 'int*' }, a2 => { schema => 'str' } }, |
| 20 |
features => { pure=>1 }, |
| 21 |
}; |
| 22 |
dd $risub->type, # "function" |
| 23 |
$risub->v, # 1.1 |
| 24 |
$risub->arg('a1'), # { schema=>'int*' } |
| 25 |
$risub->arg('a3'), # undef |
| 26 |
$risub->feature('pure'), # 1 |
| 27 |
$risub->feature('foo'), # undef |
| 28 |
$risub->langprop('summary'), # 'Calculate foo and bar' |
| 29 |
$risub->langprop({lang=>'id_ID'}, 'summary'), # 'Menghitung foo dan bar' |
| 30 |
|
| 31 |
# setting arg and property |
| 32 |
$risub->arg('a3', 'array'); # will actually fail for 1.0 metadata |
| 33 |
$risub->feature('foo', 2); # ditto |
| 34 |
|
| 35 |
# OO interface to variable metadata |
| 36 |
|
| 37 |
my $rivar = rivar { ... }; |
| 38 |
|
| 39 |
# OO interface to package metadata |
| 40 |
|
| 41 |
my $ripkg = ripkg { ... }; |
| 42 |
|
| 43 |
# OO interface to enveloped result |
| 44 |
|
| 45 |
my $envres = envres [200, "OK", [1, 2, 3]]; |
| 46 |
dd $envres->is_success, # 1 |
| 47 |
$envres->status, # 200 |
| 48 |
$envres->message, # "OK" |
| 49 |
$envres->result, # [1, 2, 3] |
| 50 |
$envres->meta; # undef |
| 51 |
|
| 52 |
# setting status, message, result, extra |
| 53 |
$envres->status(404); |
| 54 |
$envres->message('Not found'); |
| 55 |
$envres->result(undef); |
| 56 |
$envres->meta({errno=>-100}); |
| 57 |
|
| 58 |
# OO interface to function/method result metadata |
| 59 |
my $riresmeta = riresmeta { ... }; |
| 60 |
|
| 61 |
# an example of using envresmulti() |
| 62 |
sub myfunc { |
| 63 |
... |
| 64 |
|
| 65 |
my $envres = envresmulti(); |
| 66 |
|
| 67 |
# add result for each item |
| 68 |
$envres->add_result(200, "OK", {item_id=>1, payload=>"a"}); |
| 69 |
$envres->add_result(202, "OK", {item_id=>2, note=>"blah", payload=>"b"}); |
| 70 |
$envres->add_result(404, "Not found", {item_id=>3}); |
| 71 |
... |
| 72 |
|
| 73 |
# finally, return the result |
| 74 |
return $envres->as_struct; |
| 75 |
} |
| 76 |
|
| 77 |
# an example of using envrestable() |
| 78 |
sub myfunc { |
| 79 |
... |
| 80 |
my $envres = envrestable(); |
| 81 |
$envres->add_field('foo'); |
| 82 |
$envres->add_field('bar'); |
| 83 |
... |
| 84 |
return $envres->as_struct; |
| 85 |
} |
| 86 |
|
| 87 |
DESCRIPTION |
| 88 |
Rinci works using pure data structures, but sometimes it's convenient to |
| 89 |
have an object-oriented interface (wrapper) for those data. This module |
| 90 |
provides just that. |
| 91 |
|
| 92 |
FUNCTIONS |
| 93 |
rimeta $meta => OBJECT |
| 94 |
Exported by default. A shortcut for |
| 95 |
Perinci::Object::Metadata->new($meta). |
| 96 |
|
| 97 |
risub $meta => OBJECT |
| 98 |
Exported by default. A shortcut for |
| 99 |
Perinci::Object::Function->new($meta). |
| 100 |
|
| 101 |
rivar $meta => OBJECT |
| 102 |
Exported by default. A shortcut for |
| 103 |
Perinci::Object::Variable->new($meta). |
| 104 |
|
| 105 |
ripkg $meta => OBJECT |
| 106 |
Exported by default. A shortcut for |
| 107 |
Perinci::Object::Package->new($meta). |
| 108 |
|
| 109 |
envres $res => OBJECT |
| 110 |
Exported by default. A shortcut for |
| 111 |
Perinci::Object::EnvResult->new($res). |
| 112 |
|
| 113 |
envresmulti $res => OBJECT |
| 114 |
Exported by default. A shortcut for |
| 115 |
Perinci::Object::EnvResultMulti->new($res). |
| 116 |
|
| 117 |
envrestable $res => OBJECT |
| 118 |
Exported by default. A shortcut for |
| 119 |
Perinci::Object::EnvResultTable->new($res). |
| 120 |
|
| 121 |
riresmeta $resmeta => OBJECT |
| 122 |
Exported by default. A shortcut for Perinci::Object::ResMeta->new($res). |
| 123 |
|
| 124 |
HOMEPAGE |
| 125 |
Please visit the project's homepage at |
| 126 |
<https://metacpan.org/release/Perinci-Object>. |
| 127 |
|
| 128 |
SOURCE |
| 129 |
Source repository is at |
| 130 |
<https://github.com/perlancar/perl-Perinci-Object>. |
| 131 |
|
| 132 |
BUGS |
| 133 |
Please report any bugs or feature requests on the bugtracker website |
| 134 |
<https://github.com/perlancar/perl-Perinci-Object/issues> |
| 135 |
|
| 136 |
When submitting a bug or request, please include a test-file or a patch |
| 137 |
to an existing test-file that illustrates the bug or desired feature. |
| 138 |
|
| 139 |
SEE ALSO |
| 140 |
Rinci |
| 141 |
|
| 142 |
AUTHOR |
| 143 |
perlancar <[email protected]> |
| 144 |
|
| 145 |
COPYRIGHT AND LICENSE |
| 146 |
This software is copyright (c) 2021, 2017, 2016, 2015, 2014, 2013, 2012, |
| 147 |
2011 by [email protected]. |
| 148 |
|
| 149 |
This is free software; you can redistribute it and/or modify it under |
| 150 |
the same terms as the Perl 5 programming language system itself. |
| 151 |
|