/usr/share/perl5/MooseX/Traits/Util.pm is in libmoosex-traits-perl 0.12-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 | package MooseX::Traits::Util;
{
$MooseX::Traits::Util::VERSION = '0.12';
}
BEGIN {
$MooseX::Traits::Util::AUTHORITY = 'cpan:JROCKWAY';
}
use strict;
use warnings;
use Sub::Exporter -setup => {
exports => ['new_class_with_traits'],
};
use Class::Load qw(load_class);
use Carp qw(confess);
# note: "$class" throughout is "class name" or "instance of class
# name"
sub check_class {
my $class = shift;
confess "We can't interact with traits for a class ($class) ".
"that does not do MooseX::Traits" unless $class->does('MooseX::Traits');
}
sub transform_trait {
my ($class, $name) = @_;
return $1 if $name =~ /^[+](.+)$/;
check_class($class);
my $namespace = $class->meta->find_attribute_by_name('_trait_namespace');
my $base;
if($namespace->has_default){
$base = $namespace->default;
if(ref $base eq 'CODE'){
$base = $base->();
}
}
return $name unless $base;
return join '::', $base, $name;
}
sub resolve_traits {
my ($class, @traits) = @_;
check_class($class);
return map {
my $orig = $_;
if(!ref $orig){
my $transformed = transform_trait($class, $orig);
load_class($transformed);
$transformed;
}
else {
$orig;
}
} @traits;
}
my $anon_serial = 0;
sub new_class_with_traits {
my ($class, @traits) = @_;
check_class($class);
my $meta;
@traits = resolve_traits($class, @traits);
if (@traits) {
$meta = $class->meta->create(
join(q{::} => 'MooseX::Traits::__ANON__::SERIAL', ++$anon_serial),
superclasses => [ $class->meta->name ],
roles => \@traits,
cache => 1,
);
}
# if no traits were given just return the class meta
return $meta ? $meta : $class->meta;
}
1;
=for Pod::Coverage check_class new_class_with_traits resolve_traits transform_trait
=cut
|