/usr/share/perl5/MooseX/Types/Combine.pm is in libmoosex-types-perl 0.49-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 | use strict;
use warnings;
package MooseX::Types::Combine;
# ABSTRACT: Combine type libraries for exporting
our $VERSION = '0.49';
use Module::Runtime 'use_module';
use namespace::autoclean;
#pod =head1 SYNOPSIS
#pod
#pod package CombinedTypeLib;
#pod
#pod use base 'MooseX::Types::Combine';
#pod
#pod __PACKAGE__->provide_types_from(qw/TypeLib1 TypeLib2/);
#pod
#pod package UserClass;
#pod
#pod use CombinedTypeLib qw/Type1 Type2 ... /;
#pod
#pod =head1 DESCRIPTION
#pod
#pod Allows you to create a single class that will allow you to export types from
#pod multiple type libraries:
#pod
#pod package TransportTypes;
#pod
#pod use base 'MooseX::Types::Combine';
#pod
#pod __PACKAGE__->provide_types_from(qw/ MotorizedTypes UnmotorizedTypes /);
#pod
#pod 1;
#pod
#pod In this example all types defined in C<MotorizedTypes> and C<UnmotorizedTypes>
#pod are available through the C<TransportTypes> combined type library.
#pod
#pod package SkiingTrip;
#pod
#pod use Moose;
#pod
#pod use TransportTypes qw( CarType SkisType );
#pod
#pod has car => ( is => 'ro', isa => CarType, required => 1 );
#pod has ski_rack => ( is => 'ro', isa => ArrayRef[SkisType], required => 1 );
#pod ...
#pod
#pod Libraries on the right end of the list passed to L</provide_types_from> take
#pod precedence over those on the left in case of conflicts. So, in the above
#pod example if both the C<MotorizedTypes> and C<UnmotorizedTypes> libraries provided
#pod a C<Bike> type, you'd get the bicycle from C<UnmotorizedTypes> not the
#pod motorbike from C<MorotizedTypes>.
#pod
#pod You can also further combine combined type libraries with additional type
#pod libraries or other combined type libraries in the same way to provide even
#pod larger type libraries:
#pod
#pod package MeetingTransportTypes;
#pod
#pod use base 'MooseX::Types::Combine';
#pod
#pod __PACKAGE__->provide_types_from(qw/ TransportTypes TelepresenceTypes /);
#pod
#pod 1;
#pod
#pod =cut
sub import {
my ($class, @types) = @_;
my $caller = caller;
my $where_to_import_to = $caller;
if (ref $types[0] eq 'HASH') {
my $extra = shift @types;
$where_to_import_to = $extra->{-into} if exists $extra->{-into};
}
my %types = $class->_provided_types;
if ( grep { $_ eq ':all' } @types ) {
$_->import( { -into => $where_to_import_to }, q{:all} )
for $class->provide_types_from;
return;
}
my %from;
for my $type (@types) {
unless ($types{$type}) {
my @type_libs = $class->provide_types_from;
die
"$caller asked for a type ($type) which is not found in any of the"
. " type libraries (@type_libs) combined by $class\n";
}
push @{ $from{ $types{$type} } }, $type;
}
$_->import({ -into => $where_to_import_to }, @{ $from{ $_ } })
for keys %from;
}
#pod =head1 CLASS METHODS
#pod
#pod =head2 provide_types_from
#pod
#pod Sets or returns a list of type libraries (or combined type libraries) to
#pod re-export from.
#pod
#pod =cut
sub provide_types_from {
my ($class, @libs) = @_;
my $store =
do { no strict 'refs'; \@{ "${class}::__MOOSEX_TYPELIBRARY_LIBRARIES" } };
if (@libs) {
$class->_check_type_lib($_) for @libs;
@$store = @libs;
my %types = map {
my $lib = $_;
map +( $_ => $lib ), $lib->type_names
} @libs;
$class->_provided_types(%types);
}
@$store;
}
sub _check_type_lib {
my ($class, $lib) = @_;
use_module($lib);
die "Cannot use $lib in a combined type library, it does not provide any types"
unless $lib->can('type_names');
}
sub _provided_types {
my ($class, %types) = @_;
my $types =
do { no strict 'refs'; \%{ "${class}::__MOOSEX_TYPELIBRARY_TYPES" } };
%$types = %types
if keys %types;
%$types;
}
#pod =head2 type_names
#pod
#pod Returns a list of all known types by their name.
#pod
#pod =cut
sub type_names {
my ($class) = @_;
my %types = $class->_provided_types();
return keys %types;
}
#pod =head1 SEE ALSO
#pod
#pod L<MooseX::Types>
#pod
#pod =cut
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
MooseX::Types::Combine - Combine type libraries for exporting
=head1 VERSION
version 0.49
=head1 SYNOPSIS
package CombinedTypeLib;
use base 'MooseX::Types::Combine';
__PACKAGE__->provide_types_from(qw/TypeLib1 TypeLib2/);
package UserClass;
use CombinedTypeLib qw/Type1 Type2 ... /;
=head1 DESCRIPTION
Allows you to create a single class that will allow you to export types from
multiple type libraries:
package TransportTypes;
use base 'MooseX::Types::Combine';
__PACKAGE__->provide_types_from(qw/ MotorizedTypes UnmotorizedTypes /);
1;
In this example all types defined in C<MotorizedTypes> and C<UnmotorizedTypes>
are available through the C<TransportTypes> combined type library.
package SkiingTrip;
use Moose;
use TransportTypes qw( CarType SkisType );
has car => ( is => 'ro', isa => CarType, required => 1 );
has ski_rack => ( is => 'ro', isa => ArrayRef[SkisType], required => 1 );
...
Libraries on the right end of the list passed to L</provide_types_from> take
precedence over those on the left in case of conflicts. So, in the above
example if both the C<MotorizedTypes> and C<UnmotorizedTypes> libraries provided
a C<Bike> type, you'd get the bicycle from C<UnmotorizedTypes> not the
motorbike from C<MorotizedTypes>.
You can also further combine combined type libraries with additional type
libraries or other combined type libraries in the same way to provide even
larger type libraries:
package MeetingTransportTypes;
use base 'MooseX::Types::Combine';
__PACKAGE__->provide_types_from(qw/ TransportTypes TelepresenceTypes /);
1;
=head1 CLASS METHODS
=head2 provide_types_from
Sets or returns a list of type libraries (or combined type libraries) to
re-export from.
=head2 type_names
Returns a list of all known types by their name.
=head1 SEE ALSO
L<MooseX::Types>
=head1 SUPPORT
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types>
(or L<bug-MooseX-Types@rt.cpan.org|mailto:bug-MooseX-Types@rt.cpan.org>).
There is also a mailing list available for users of this distribution, at
L<http://lists.perl.org/list/moose.html>.
There is also an irc channel available for users of this distribution, at
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
=head1 AUTHOR
Robert "phaylon" Sedlacek <rs@474.at>
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2007 by Robert "phaylon" Sedlacek.
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
|