/usr/share/perl5/Exporter/Declare/Meta.pm is in libexporter-declare-perl 0.114-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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | package Exporter::Declare::Meta;
use strict;
use warnings;
use Scalar::Util qw/blessed reftype/;
use Carp qw/croak/;
use aliased 'Exporter::Declare::Export::Sub';
use aliased 'Exporter::Declare::Export::Variable';
use aliased 'Exporter::Declare::Export::Alias';
use Meta::Builder;
accessor 'export_meta';
hash_metric exports => (
add => sub {
my $self = shift;
my ( $data, $metric, $action, $item, $ref ) = @_;
croak "Exports must be instances of 'Exporter::Declare::Export'"
unless blessed($ref) && $ref->isa('Exporter::Declare::Export');
my ( $type, $name ) = ( $item =~ m/^([\&\%\@\$])?(.*)$/ );
$type ||= '&';
my $fullname = "$type$name";
$self->default_hash_add( $data, $metric, $action, $fullname, $ref );
push @{$self->export_tags->{all}} => $fullname;
},
get => sub {
my $self = shift;
my ( $data, $metric, $action, $item ) = @_;
croak "exports_get() does not accept a tag as an argument"
if $item =~ m/^[:-]/;
my ( $type, $name ) = ( $item =~ m/^([\&\%\@\$])?(.*)$/ );
$type ||= '&';
my $fullname = "$type$name";
return $self->default_hash_get( $data, $metric, $action, $fullname )
|| croak $self->package . " does not export '$fullname'";
},
merge => sub {
my $self = shift;
my ( $data, $metric, $action, $merge ) = @_;
my $newmerge = {};
for my $item ( keys %$merge ) {
my $value = $merge->{$item};
next if $value->isa(Alias);
next if $data->{$item};
$newmerge->{$item} = $value;
}
$self->default_hash_merge( $data, $metric, $action, $newmerge );
},
list => sub {
my $self = shift;
my ($data) = @_;
return keys %$data;
},
);
hash_metric options => (
add => sub {
my $self = shift;
my ( $data, $metric, $action, $item ) = @_;
croak "'$item' is already a tag, you can't also make it an option."
if $self->export_tags_has($item);
croak "'$item' is already an argument, you can't also make it an option."
if $self->arguments_has($item);
$self->default_hash_add( $data, $metric, $action, $item, 1 );
},
list => sub {
my $self = shift;
my ($data) = @_;
return keys %$data;
},
);
hash_metric arguments => (
add => sub {
my $self = shift;
my ( $data, $metric, $action, $item ) = @_;
croak "'$item' is already a tag, you can't also make it an argument."
if $self->export_tags_has($item);
croak "'$item' is already an option, you can't also make it an argument."
if $self->options_has($item);
$self->default_hash_add( $data, $metric, $action, $item, 1 );
},
merge => sub {
my $self = shift;
my ( $data, $metric, $action, $merge ) = @_;
my $newmerge = {%$merge};
delete $newmerge->{suffix};
delete $newmerge->{prefix};
$self->default_hash_merge( $data, $metric, $action, $newmerge );
},
list => sub {
my $self = shift;
my ($data) = @_;
return keys %$data;
},
);
lists_metric export_tags => (
push => sub {
my $self = shift;
my ( $data, $metric, $action, $item, @args ) = @_;
croak "'$item' is a reserved tag, you cannot override it."
if $item eq 'all';
croak "'$item' is already an option, you can't also make it a tag."
if $self->options_has($item);
croak "'$item' is already an argument, you can't also make it a tag."
if $self->arguments_has($item);
$self->default_list_push( $data, $metric, $action, $item, @args );
},
merge => sub {
my $self = shift;
my ( $data, $metric, $action, $merge ) = @_;
my $newmerge = {};
my %aliases = (
map {
my ($name) = (m/^&?(.*)$/);
( $name => 1, "&$name" => 1 )
} @{$merge->{alias}}
);
for my $item ( keys %$merge ) {
my $values = $merge->{$item};
$newmerge->{$item} = [grep { !$aliases{$_} } @$values];
}
$self->default_list_merge( $data, $metric, $action, $newmerge );
},
list => sub {
my $self = shift;
my ($data) = @_;
return keys %$data;
},
);
sub new {
my $class = shift;
my $self = $class->SUPER::new(
@_,
export_tags => {all => [], default => [], alias => []},
arguments => {prefix => 1, suffix => 1},
);
$self->add_alias;
return $self;
}
sub new_from_exporter {
my $class = shift;
my ($exporter) = @_;
my $self = $class->new($exporter);
my %seen;
my ($exports) = $self->get_ref_from_package('@EXPORT');
my ($export_oks) = $self->get_ref_from_package('@EXPORT_OK');
my ($tags) = $self->get_ref_from_package('%EXPORT_TAGS');
$self->exports_add(@$_) for map {
my ( $ref, $name ) = $self->get_ref_from_package($_);
if ( $name =~ m/^\&/ ) {
Sub->new( $ref, exported_by => $exporter );
}
else {
Variable->new( $ref, exported_by => $exporter );
}
[$name, $ref];
} grep { !$seen{$_}++ } @$exports, @$export_oks;
$self->export_tags_push( 'default', @$exports )
if @$exports;
$self->export_tags_push( $_, $tags->{$_} ) for keys %$tags;
return $self;
}
sub add_alias {
my $self = shift;
my $package = $self->package;
my ($alias) = ( $package =~ m/([^:]+)$/ );
$self->exports_add( $alias, Alias->new( sub { $package }, exported_by => $package ) );
$self->export_tags_push( 'alias', $alias );
}
sub is_tag {
my $self = shift;
my ($name) = @_;
return exists $self->export_tags->{$name} ? 1 : 0;
}
sub is_argument {
my $self = shift;
my ($name) = @_;
return exists $self->arguments->{$name} ? 1 : 0;
}
sub is_option {
my $self = shift;
my ($name) = @_;
return exists $self->options->{$name} ? 1 : 0;
}
sub get_ref_from_package {
my $self = shift;
my ($item) = @_;
use Carp qw/confess/;
confess unless $item;
my ( $type, $name ) = ( $item =~ m/^([\&\@\%\$]?)(.*)$/ );
$type ||= '&';
my $fullname = "$type$name";
my $ref = $self->package . '::' . $name;
no strict 'refs';
return ( \&{$ref}, $fullname ) if !$type || $type eq '&';
return ( \${$ref}, $fullname ) if $type eq '$';
return ( \@{$ref}, $fullname ) if $type eq '@';
return ( \%{$ref}, $fullname ) if $type eq '%';
croak "'$item' cannot be exported";
}
sub reexport {
my $self = shift;
my ($exporter) = @_;
my $meta =
$exporter->can('export_meta')
? $exporter->export_meta()
: __PACKAGE__->new_from_exporter($exporter);
$self->merge($meta);
}
1;
=head1 NAME
Exporter::Declare::Meta - The meta object which stores meta-data for all
exporters.
=head1 DESCRIPTION
All classes that use Exporter::Declare have an associated Meta object. Meta
objects track available exports, tags, and options.
=head1 METHODS
=over 4
=item $class->new( $package )
Created a meta object for the specified package. Also injects the export_meta()
sub into the package namespace that returns the generated meta object.
=item $class->new_from_exporter( $package )
Create a meta object for a package that already uses Exporter.pm. This will not
turn the class into an Exporter::Declare package, but it will create a meta
object and export_meta() method on it. This si primarily used for reexport
purposes.
=item $package = $meta->package()
Get the name of the package with which the meta object is associated.
=item $meta->add_alias()
Usually called at construction to add a package alias function to the exports.
=item $meta->add_export( $name, $ref )
Add an export, name should be the item name with sigil (assumed to be sub if
there is no sigil). $ref should be a ref blessed as an
L<Exporter::Declare::Export> subclass.
=item $meta->get_export( $name )
Retrieve the L<Exporter::Declare::Export> object by name. Name should be the
item name with sigil, assumed to be sub when sigil is missing.
=item $meta->export_tags_push( $name, @items )
Add @items to the specified tag. Tag will be created if it does not already
exist. $name should be the tag name B<WITHOUT> -/: prefix.
=item @list = $meta->export_tags_get( $name )
Get the list of items associated with the specified tag. $name should be the
tag name B<WITHOUT> -/: prefix.
=item @list = $meta->export_tags_list()
Get a list of all export tags.
=item $bool = $meta->is_tag( $name )
Check if a tag with the given name exists. $name should be the tag name
B<WITHOUT> -/: prefix.
=item $meta->options_add( $name )
Add import options by name. These will be boolean options that take no
arguments.
=item my @list = $meta->options_list()
=item $meta->arguments_add( $name )
Add import options that slurp in the next argument as a value.
=item $bool = $meta->is_option( $name )
Check if the specified name is an option.
=item $bool = $meta->is_argument( $name )
Check if the specified name is an option that takes an argument.
=item $meta->add_parser( $name, sub { ... })
Add a parser sub that should be associated with exports via L<Devel::Declare>
=item $meta->get_parser( $name )
Get a parser by name.
=item $ref = $meta->get_ref_from_package( $item )
Returns a reference to a specific package variable or sub.
=item $meta->reexport( $package )
Re-export the exports in the provided package. Package may be an
L<Exporter::Declare> based package or an L<Exporter> based package.
=item $meta->merge( $meta2 )
Merge-in the exports and tags of the second meta object.
=back
=head1 AUTHORS
Chad Granum L<exodist7@gmail.com>
=head1 COPYRIGHT
Copyright (C) 2010 Chad Granum
Exporter-Declare is free software; Standard perl licence.
Exporter-Declare is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
|