/usr/share/perl5/Perinci/Object/Metadata.pm is in libperinci-object-perl 0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | package Perinci::Object::Metadata;
use 5.010;
use strict;
use warnings;
use SHARYANTO::String::Util qw(trim_blank_lines);
our $VERSION = '0.13'; # VERSION
sub new {
my ($class, $meta) = @_;
$meta //= {};
my $obj = \$meta;
bless $obj, $class;
}
sub v {
my $self = shift;
${$self}->{v} // 1.0;
}
sub type {
die "BUG: type() must be subclassed";
}
sub as_struct {
my $self = shift;
${$self};
}
sub langprop {
my ($self, $prop, $opts) = @_;
$opts //= {};
my $deflang = ${$self}->{default_lang} // "en_US";
my $olang = $opts->{lang} || $ENV{LANGUAGE} || $ENV{LANG} || $deflang;
$olang =~ s/\W.+//; # change "en_US.UTF-8" to "en_US"
my $mark = $opts->{mark_different_lang} // 1;
#print "deflang=$deflang, olang=$olang, mark_different_lang=$mark\n";
my @k;
if ($olang eq $deflang) {
@k = ([$olang, $prop, 0]);
} else {
@k = ([$olang, "$prop.alt.lang.$olang", 0], [$deflang, $prop, $mark]);
}
for my $k (@k) {
#print "k=".join(", ", @$k)."\n";
my $v = ${$self}->{$k->[1]};
if (defined $v) {
if ($k->[2]) {
my $has_nl = $v =~ s/\n\z//;
$v = "{$k->[0] $v}" . ($has_nl ? "\n" : "");
}
return trim_blank_lines($v);
}
}
return undef;
}
1;
# ABSTRACT: Base class for Perinci::Object metadata classes
__END__
=pod
=encoding UTF-8
=head1 NAME
Perinci::Object::Metadata - Base class for Perinci::Object metadata classes
=head1 VERSION
version 0.13
=head1 METHODS
=head2 v
=head2 as_struct
=head2 langprop($prop, \%opts)
Get property value in the specified language (i.e., either in C<prop> or
C<prop.alt.lang.XXX> properties).
Known options:
=over 4
=item * lang => STR
Defaults to metadata's C<default_lang> (which in turns default to C<en_US> if
unspecified).
=item * mark_different_lang => BOOL (defaults to 1)
If set to true, text with different language than the language requested will be
marked, e.g. C<"I love you"> requested in Indonesian language where the value
for that language is unavailable will result in C<"{en_US I love you}"> being
returned.
=back
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Object>.
=head1 SOURCE
Source repository is at L<https://github.com/sharyanto/perl-Perinci-Object>.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Object>
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
=head1 AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|