Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up

  • Loading branch information...
commit f7fca2b29ab612699f8dd305c5d817f760306704 1 parent c38c1b2
@avuserow authored
Showing with 177 additions and 9,242 deletions.
  1. +5 −0 Changes
  2. +64 −0 MANIFEST
  3. +0 −13 Makefile
  4. +23 −0 Makefile.PL
  5. +55 −0 README
  6. +10 −0 ignore.txt
  7. +2 −0  lib/Acoustics.pm
  8. +0 −440 lib/Mouse.pm
  9. +0 −319 lib/Mouse/Exporter.pm
  10. +0 −575 lib/Mouse/Meta/Attribute.pm
  11. +0 −553 lib/Mouse/Meta/Class.pm
  12. +0 −52 lib/Mouse/Meta/Method.pm
  13. +0 −185 lib/Mouse/Meta/Method/Accessor.pm
  14. +0 −206 lib/Mouse/Meta/Method/Constructor.pm
  15. +0 −43 lib/Mouse/Meta/Method/Delegation.pm
  16. +0 −62 lib/Mouse/Meta/Method/Destructor.pm
  17. +0 −325 lib/Mouse/Meta/Module.pm
  18. +0 −339 lib/Mouse/Meta/Role.pm
  19. +0 −129 lib/Mouse/Meta/Role/Composite.pm
  20. +0 −33 lib/Mouse/Meta/Role/Method.pm
  21. +0 −240 lib/Mouse/Meta/TypeConstraint.pm
  22. +0 −107 lib/Mouse/Object.pm
  23. +0 −577 lib/Mouse/PurePerl.pm
  24. +0 −221 lib/Mouse/Role.pm
  25. +0 −140 lib/Mouse/Spec.pm
  26. +0 −33 lib/Mouse/TypeRegistry.pm
  27. +0 −413 lib/Mouse/Util.pm
  28. +0 −184 lib/Mouse/Util/MetaRole.pm
  29. +0 −554 lib/Mouse/Util/TypeConstraints.pm
  30. +0 −35 lib/Mouse/XS.pod
  31. +0 −2,664 lib/SQL/Abstract.pm
  32. +0 −582 lib/SQL/Abstract/Test.pm
  33. +0 −88 lib/Squirrel.pm
  34. +0 −47 lib/Squirrel/Role.pm
  35. +0 −83 lib/ouse.pm
  36. +18 −0 t/use_ok.t
View
5 Changes
@@ -0,0 +1,5 @@
+Revision history for Acoustics
+
+0.01 Date/time
+ First version, released on an unsuspecting world.
+
View
64 MANIFEST
@@ -0,0 +1,64 @@
+Makefile.PL
+Changes
+MANIFEST
+README
+lib/Acoustics.pm
+lib/Acoustics/Scanner.pm
+lib/Acoustics/Web/Auth/Simple.pm
+lib/Acoustics/Web/Auth/Kerberos.pm
+lib/Acoustics/Web/Auth.pm
+lib/Acoustics/RPC/Remctl.pm
+lib/Acoustics/RPC/SSH_PrivateKey.pm
+lib/Acoustics/RPC/Local.pm
+lib/Acoustics/Queue/RoundRobin.pm
+lib/Acoustics/Queue/TimeSlice.pm
+lib/Acoustics/Database.pm
+lib/Acoustics/Web.pm
+lib/Acoustics/Queue.pm
+lib/Acoustics/Player/Icecast.pm
+lib/Acoustics/Player/MPlayer.pm
+lib/Acoustics/Test.pm
+www-data/auth/index.pl
+www-data/auth/.htaccess
+www-data/mustache-min.js
+www-data/underscore-min.js
+www-data/gradient.png
+www-data/acoustics.css
+www-data/amp.png
+www-data/icons/README
+www-data/icons/music.png
+www-data/icons/sport_8ball.png
+www-data/icons/hourglass.png
+www-data/icons/delete.png
+www-data/icons/disconnect.png
+www-data/icons/cd.png
+www-data/icons/database_lightning.png
+www-data/icons/controls/control-stop-square.png
+www-data/icons/controls/skip2.png
+www-data/icons/controls/play2.png
+www-data/icons/controls/control-skip.png
+www-data/icons/controls/stop2.png
+www-data/icons/controls/control.png
+www-data/icons/lightning_go.png
+www-data/icons/as.png
+www-data/icons/bomb.png
+www-data/icons/user.png
+www-data/icons/sound.png
+www-data/icons/wrench_orange.png
+www-data/icons/favicon.ico
+www-data/icons/new.png
+www-data/icons/wiki.png
+www-data/icons/add.png
+www-data/acoustics.js
+www-data/jquery.min.js
+www-data/jquery.tablesorter.min.js
+www-data/sprintf-min.js
+bin/streaming-next-song.sh
+bin/initdb-pgsql.pl
+bin/player-remote.pl
+bin/tagreader.cpp
+bin/initdb-mysql.pl
+bin/Makefile
+bin/k5start-wrapper.sh
+bin/garbage-collect.pl
+bin/scanner.pl
View
13 Makefile
@@ -1,13 +0,0 @@
-export PERL5OPT = -Ilib
-export ACOUSTICS_CONFIG_FILE = conf/acoustics_test.ini
-
-# this gets set when we're run under 'cover -test'
-# so it's pretty reliable as a sign to add this flag
-ifdef OTHERLDFLAGS
- export HARNESS_PERL_SWITCHES=-MDevel::Cover=-ignore,.,-select,Acoustics
-endif
-
-test:
- prove t/init.pl
- prove -s -r -j 3 t/
- chmod -R 755 cover_db
View
23 Makefile.PL
@@ -0,0 +1,23 @@
+use inc::Module::Install;
+
+name 'Acoustics';
+all_from 'lib/Acoustics.pm';
+author q{Adrian Kreher <avuserow@cpan.org>};
+license 'perl';
+
+test_requires 'Test::More';
+
+#install_script 'bin/streaming-next-song.sh';
+#install_script 'bin/initdb-pgsql.pl';
+install_script 'bin/player-remote.pl';
+install_script 'bin/initdb-mysql.pl';
+install_script 'bin/k5start-wrapper.sh';
+install_script 'bin/garbage-collect.pl';
+install_script 'bin/scanner.pl';
+
+install_share 'www-data';
+
+auto_install;
+
+WriteAll;
+
View
55 README
@@ -0,0 +1,55 @@
+Acoustics
+
+The README is used to introduce the module and provide instructions on
+how to install the module, any machine dependencies it may have (for
+example C compilers and installed libraries) and any other information
+that should be provided before the module is installed.
+
+A README file is required for CPAN modules since CPAN extracts the README
+file from a module distribution so that people browsing the archive
+can use it to get an idea of the module's uses. It is usually a good idea
+to provide version information here so that people can decide whether
+fixes for the module are worth downloading.
+
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Build.PL
+ ./Build
+ ./Build test
+ ./Build install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+ perldoc Acoustics
+
+You can also look for information at:
+
+ RT, CPAN's request tracker
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acoustics
+
+ AnnoCPAN, Annotated CPAN documentation
+ http://annocpan.org/dist/Acoustics
+
+ CPAN Ratings
+ http://cpanratings.perl.org/d/Acoustics
+
+ Search CPAN
+ http://search.cpan.org/dist/Acoustics/
+
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2010 Adrian Kreher
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
View
10 ignore.txt
@@ -0,0 +1,10 @@
+blib*
+Makefile
+Makefile.old
+Build
+_build*
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+Acoustics-*
+cover_db
View
2  lib/Acoustics.pm
@@ -3,6 +3,8 @@ package Acoustics;
use strict;
use warnings;
+our $VERSION = '0.01';
+
use Acoustics::Database;
use Mouse;
use Module::Load 'load';
View
440 lib/Mouse.pm
@@ -1,440 +0,0 @@
-package Mouse;
-use 5.006_002;
-
-use Mouse::Exporter; # enables strict and warnings
-
-our $VERSION = '0.42';
-
-use Carp qw(confess);
-use Scalar::Util qw(blessed);
-
-use Mouse::Util qw(load_class is_class_loaded get_code_package not_supported);
-
-use Mouse::Meta::Module;
-use Mouse::Meta::Class;
-use Mouse::Meta::Role;
-use Mouse::Meta::Attribute;
-use Mouse::Object;
-use Mouse::Util::TypeConstraints ();
-
-Mouse::Exporter->setup_import_methods(
- as_is => [qw(
- extends with
- has
- before after around
- override super
- augment inner
- ),
- \&Scalar::Util::blessed,
- \&Carp::confess,
- ],
-);
-
-
-sub extends {
- Mouse::Meta::Class->initialize(scalar caller)->superclasses(@_);
- return;
-}
-
-sub with {
- Mouse::Util::apply_all_roles(scalar(caller), @_);
- return;
-}
-
-sub has {
- my $meta = Mouse::Meta::Class->initialize(scalar caller);
- my $name = shift;
-
- $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
- if @_ % 2; # odd number of arguments
-
- if(ref $name){ # has [qw(foo bar)] => (...)
- for (@{$name}){
- $meta->add_attribute($_ => @_);
- }
- }
- else{ # has foo => (...)
- $meta->add_attribute($name => @_);
- }
- return;
-}
-
-sub before {
- my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
- my $code = pop;
-
- for (@_) {
- $meta->add_before_method_modifier($_ => $code);
- }
- return;
-}
-
-sub after {
- my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
- my $code = pop;
-
- for (@_) {
- $meta->add_after_method_modifier($_ => $code);
- }
- return;
-}
-
-sub around {
- my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
- my $code = pop;
-
- for (@_) {
- $meta->add_around_method_modifier($_ => $code);
- }
- return;
-}
-
-our $SUPER_PACKAGE;
-our $SUPER_BODY;
-our @SUPER_ARGS;
-
-sub super {
- # This check avoids a recursion loop - see
- # t/100_bugs/020_super_recursion.t
- return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller();
- return if !defined $SUPER_BODY;
- $SUPER_BODY->(@SUPER_ARGS);
-}
-
-sub override {
- # my($name, $method) = @_;
- Mouse::Meta::Class->initialize(scalar caller)->add_override_method_modifier(@_);
-}
-
-our %INNER_BODY;
-our %INNER_ARGS;
-
-sub inner {
- my $pkg = caller();
- if ( my $body = $INNER_BODY{$pkg} ) {
- my $args = $INNER_ARGS{$pkg};
- local $INNER_ARGS{$pkg};
- local $INNER_BODY{$pkg};
- return $body->(@{$args});
- }
- else {
- return;
- }
-}
-
-sub augment {
- #my($name, $method) = @_;
- Mouse::Meta::Class->initialize(scalar caller)->add_augment_method_modifier(@_);
- return;
-}
-
-sub init_meta {
- shift;
- my %args = @_;
-
- my $class = $args{for_class}
- or confess("Cannot call init_meta without specifying a for_class");
-
- my $base_class = $args{base_class} || 'Mouse::Object';
- my $metaclass = $args{metaclass} || 'Mouse::Meta::Class';
-
- my $meta = $metaclass->initialize($class);
-
- $meta->add_method(meta => sub{
- return $metaclass->initialize(ref($_[0]) || $_[0]);
- });
-
- $meta->superclasses($base_class)
- unless $meta->superclasses;
-
- # make a class type for each Mouse class
- Mouse::Util::TypeConstraints::class_type($class)
- unless Mouse::Util::TypeConstraints::find_type_constraint($class);
-
- return $meta;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse - Moose minus the antlers
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 SYNOPSIS
-
- package Point;
- use Mouse; # automatically turns on strict and warnings
-
- has 'x' => (is => 'rw', isa => 'Int');
- has 'y' => (is => 'rw', isa => 'Int');
-
- sub clear {
- my $self = shift;
- $self->x(0);
- $self->y(0);
- }
-
- package Point3D;
- use Mouse;
-
- extends 'Point';
-
- has 'z' => (is => 'rw', isa => 'Int');
-
- after 'clear' => sub {
- my $self = shift;
- $self->z(0);
- };
-
-=head1 DESCRIPTION
-
-L<Moose> is wonderful. B<Use Moose instead of Mouse.>
-
-Unfortunately, Moose has a compile-time penalty. Though significant progress
-has been made over the years, the compile time penalty is a non-starter for
-some very specific applications. If you are writing a command-line application
-or CGI script where startup time is essential, you may not be able to use
-Moose. We recommend that you instead use L<HTTP::Engine> and FastCGI for the
-latter, if possible.
-
-Mouse aims to alleviate this by providing a subset of Moose's functionality,
-faster.
-
-We're also going as light on dependencies as possible. Mouse currently has
-B<no dependencies> except for testing modules.
-
-=head2 MOOSE COMPATIBILITY
-
-Compatibility with Moose has been the utmost concern. Fewer than 1% of the
-tests fail when run against Moose instead of Mouse. Mouse code coverage is also
-over 96%. Even the error messages are taken from Moose. The Mouse code just
-runs the test suite 4x faster.
-
-The idea is that, if you need the extra power, you should be able to run
-C<s/Mouse/Moose/g> on your codebase and have nothing break. To that end,
-we have written L<Any::Moose> which will act as Mouse unless Moose is loaded,
-in which case it will act as Moose. Since Mouse is a little sloppier than
-Moose, if you run into weird errors, it would be worth running:
-
- ANY_MOOSE=Moose perl your-script.pl
-
-to see if the bug is caused by Mouse. Moose's diagnostics and validation are
-also much better.
-
-See also L<Mouse::Spec> for compatibility and incompatibility with Moose.
-
-=head2 MouseX
-
-Please don't copy MooseX code to MouseX. If you need extensions, you really
-should upgrade to Moose. We don't need two parallel sets of extensions!
-
-If you really must write a Mouse extension, please contact the Moose mailing
-list or #moose on IRC beforehand.
-
-=head1 KEYWORDS
-
-=head2 C<< $object->meta -> Mouse::Meta::Class >>
-
-Returns this class' metaclass instance.
-
-=head2 C<< extends superclasses >>
-
-Sets this class' superclasses.
-
-=head2 C<< before (method|methods) => CodeRef >>
-
-Installs a "before" method modifier. See L<Moose/before>.
-
-=head2 C<< after (method|methods) => CodeRef >>
-
-Installs an "after" method modifier. See L<Moose/after>.
-=head2 C<< around (method|methods) => CodeRef >>
-
-Installs an "around" method modifier. See L<Moose/around>.
-=head2 C<< has (name|names) => parameters >>
-
-Adds an attribute (or if passed an arrayref of names, multiple attributes) to
-this class. Options:
-
-=over 4
-
-=item C<< is => ro|rw|bare >>
-
-If specified, inlines a read-only/read-write accessor with the same name as
-the attribute.
-
-=item C<< isa => TypeConstraint >>
-
-Provides type checking in the constructor and accessor. The following types are
-supported. Any unknown type is taken to be a class check
-(e.g. C<< isa => 'DateTime' >> would accept only L<DateTime> objects).
-
- Any Item Bool Undef Defined Value Num Int Str ClassName
- Ref ScalarRef ArrayRef HashRef CodeRef RegexpRef GlobRef
- FileHandle Object
-
-For more documentation on type constraints, see L<Mouse::Util::TypeConstraints>.
-
-
-=item C<< required => Bool >>
-
-Whether this attribute is required to have a value. If the attribute is lazy or
-has a builder, then providing a value for the attribute in the constructor is
-optional.
-
-=item C<< init_arg => Str | Undef >>
-
-Allows you to use a different key name in the constructor. If undef, the
-attribute can't be passed to the constructor.
-
-=item C<< default => Value | CodeRef >>
-
-Sets the default value of the attribute. If the default is a coderef, it will
-be invoked to get the default value. Due to quirks of Perl, any bare reference
-is forbidden, you must wrap the reference in a coderef. Otherwise, all
-instances will share the same reference.
-
-=item C<< lazy => Bool >>
-
-If specified, the default is calculated on demand instead of in the
-constructor.
-
-=item C<< predicate => Str >>
-
-Lets you specify a method name for installing a predicate method, which checks
-that the attribute has a value. It will not invoke a lazy default or builder
-method.
-
-=item C<< clearer => Str >>
-
-Lets you specify a method name for installing a clearer method, which clears
-the attribute's value from the instance. On the next read, lazy or builder will
-be invoked.
-
-=item C<< handles => HashRef|ArrayRef >>
-
-Lets you specify methods to delegate to the attribute. ArrayRef forwards the
-given method names to method calls on the attribute. HashRef maps local method
-names to remote method names called on the attribute. Other forms of
-L</handles>, such as regular expression and coderef, are not yet supported.
-
-=item C<< weak_ref => Bool >>
-
-Lets you automatically weaken any reference stored in the attribute.
-
-Use of this feature requires L<Scalar::Util>!
-
-=item C<< trigger => CodeRef >>
-
-Any time the attribute's value is set (either through the accessor or the constructor), the trigger is called on it. The trigger receives as arguments the instance, the new value, and the attribute instance.
-
-=item C<< builder => Str >>
-
-Defines a method name to be called to provide the default value of the
-attribute. C<< builder => 'build_foo' >> is mostly equivalent to
-C<< default => sub { $_[0]->build_foo } >>.
-
-=item C<< auto_deref => Bool >>
-
-Allows you to automatically dereference ArrayRef and HashRef attributes in list
-context. In scalar context, the reference is returned (NOT the list length or
-bucket status). You must specify an appropriate type constraint to use
-auto_deref.
-
-=item C<< lazy_build => Bool >>
-
-Automatically define the following options:
-
- has $attr => (
- # ...
- lazy => 1
- builder => "_build_$attr",
- clearer => "clear_$attr",
- predicate => "has_$attr",
- );
-
-=back
-
-=head2 C<< confess(message) -> BOOM >>
-
-L<Carp/confess> for your convenience.
-
-=head2 C<< blessed(value) -> ClassName | undef >>
-
-L<Scalar::Util/blessed> for your convenience.
-
-=head1 MISC
-
-=head2 import
-
-Importing Mouse will default your class' superclass list to L<Mouse::Object>.
-You may use L</extends> to replace the superclass list.
-
-=head2 unimport
-
-Please unimport Mouse (C<no Mouse>) so that if someone calls one of the
-keywords (such as L</extends>) it will break loudly instead breaking subtly.
-
-=head1 SOURCE CODE ACCESS
-
-We have a public git repository:
-
- git clone git://git.moose.perl.org/Mouse.git
-
-=head1 DEPENDENCIES
-
-Perl 5.6.2 or later.
-
-=head1 SEE ALSO
-
-L<Mouse::Spec>
-
-L<Moose>
-
-L<Moose::Manual>
-
-L<Moose::Cookbook>
-
-L<Class::MOP>
-
-=head1 AUTHORS
-
-Shawn M Moore E<lt>sartak at gmail.comE<gt>
-
-Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
-
-tokuhirom
-
-Yappo
-
-wu-lee
-
-Goro Fuji (gfx) E<lt>gfuji at cpan.orgE<gt>
-
-with plenty of code borrowed from L<Class::MOP> and L<Moose>
-
-=head1 BUGS
-
-All complex software has bugs lurking in it, and this module is no exception.
-Please report any bugs to C<bug-mouse at rt.cpan.org>, or through the web
-interface at L<http://rt.cpan.org/Public/Dist/Display.html?Name=Mouse>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2008-2009 Infinity Interactive, Inc.
-
-http://www.iinteractive.com/
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-=cut
-
View
319 lib/Mouse/Exporter.pm
@@ -1,319 +0,0 @@
-package Mouse::Exporter;
-use strict;
-use warnings;
-
-use Carp qw(confess);
-
-my %SPEC;
-
-use constant _strict_bits => strict::bits(qw(subs refs vars));
-
-# it must be "require", because Mouse::Util depends on Mouse::Exporter,
-# which depends on Mouse::Util::import()
-require Mouse::Util;
-
-sub import{
- $^H |= _strict_bits; # strict->import;
- ${^WARNING_BITS} |= $warnings::Bits{all}; # warnings->import;
- return;
-}
-
-
-sub setup_import_methods{
- my($class, %args) = @_;
-
- my $exporting_package = $args{exporting_package} ||= caller();
-
- my($import, $unimport) = $class->build_import_methods(%args);
-
- no strict 'refs';
-
- *{$exporting_package . '::import'} = $import;
- *{$exporting_package . '::unimport'} = $unimport;
-
- # for backward compatibility
- *{$exporting_package . '::export_to_level'} = sub{
- my($package, $level, undef, @args) = @_; # the third argument is redundant
- $package->import({ into_level => $level + 1 }, @args);
- };
- *{$exporting_package . '::export'} = sub{
- my($package, $into, @args) = @_;
- $package->import({ into => $into }, @args);
- };
- return;
-}
-
-sub build_import_methods{
- my($class, %args) = @_;
-
- my $exporting_package = $args{exporting_package} ||= caller();
-
- $SPEC{$exporting_package} = \%args;
-
- # canonicalize args
- my @export_from;
- if($args{also}){
- my %seen;
- my @stack = ($exporting_package);
-
- while(my $current = shift @stack){
- push @export_from, $current;
-
- my $also = $SPEC{$current}{also} or next;
- push @stack, grep{ !$seen{$_}++ } ref($also) ? @{ $also } : $also;
- }
- }
- else{
- @export_from = ($exporting_package);
- }
-
- {
- my %exports;
- my @removables;
- my @all;
-
- my @init_meta_methods;
-
- foreach my $package(@export_from){
- my $spec = $SPEC{$package} or next;
-
- if(my $as_is = $spec->{as_is}){
- foreach my $thingy (@{$as_is}){
- my($code_package, $code_name, $code);
-
- if(ref($thingy)){
- $code = $thingy;
- ($code_package, $code_name) = Mouse::Util::get_code_info($code);
- }
- else{
- no strict 'refs';
- $code_package = $package;
- $code_name = $thingy;
- $code = \&{ $code_package . '::' . $code_name };
- }
-
- push @all, $code_name;
- $exports{$code_name} = $code;
- if($code_package eq $package){
- push @removables, $code_name;
- }
- }
- }
-
- if(my $init_meta = $package->can('init_meta')){
- if(!grep{ $_ == $init_meta } @init_meta_methods){
- push @init_meta_methods, $init_meta;
- }
- }
- }
- $args{EXPORTS} = \%exports;
- $args{REMOVABLES} = \@removables;
-
- $args{groups}{all} ||= \@all;
-
- if(my $default_list = $args{groups}{default}){
- my %default;
- foreach my $keyword(@{$default_list}){
- $default{$keyword} = $exports{$keyword}
- || confess(qq{The $exporting_package package does not export "$keyword"});
- }
- $args{DEFAULT} = \%default;
- }
- else{
- $args{groups}{default} ||= \@all;
- $args{DEFAULT} = $args{EXPORTS};
- }
-
- if(@init_meta_methods){
- $args{INIT_META} = \@init_meta_methods;
- }
- }
-
- return (\&do_import, \&do_unimport);
-}
-
-
-# the entity of general import()
-sub do_import {
- my($package, @args) = @_;
-
- my $spec = $SPEC{$package}
- || confess("The package $package package does not use Mouse::Exporter");
-
- my $into = _get_caller_package(ref($args[0]) ? shift @args : undef);
-
- my @exports;
- my @traits;
-
- while(@args){
- my $arg = shift @args;
- if($arg =~ s/^-//){
- if($arg eq 'traits'){
- push @traits, ref($args[0]) ? @{shift(@args)} : shift(@args);
- }
- else {
- Mouse::Util::not_supported("-$arg");
- }
- }
- elsif($arg =~ s/^://){
- my $group = $spec->{groups}{$arg}
- || confess(qq{The $package package does not export the group "$arg"});
- push @exports, @{$group};
- }
- else{
- push @exports, $arg;
- }
- }
-
- $^H |= _strict_bits; # strict->import;
- ${^WARNING_BITS} |= $warnings::Bits{all}; # warnings->import;
-
- if($spec->{INIT_META}){
- my $meta;
- foreach my $init_meta(@{$spec->{INIT_META}}){
- $meta = $into->$init_meta(for_class => $into);
- }
-
- if(@traits){
- my $type = (split /::/, ref $meta)[-1]; # e.g. "Class" for "My::Meta::Class"
- @traits =
- map{
- ref($_) ? $_
- : Mouse::Util::resolve_metaclass_alias($type => $_, trait => 1)
- } @traits;
-
- require Mouse::Util::MetaRole;
- Mouse::Util::MetaRole::apply_metaclass_roles(
- for_class => $into,
- metaclass_roles => \@traits,
- );
- }
- }
- elsif(@traits){
- Carp::confess("Cannot provide traits when $package does not have an init_meta() method");
- }
-
- if(@exports){
- foreach my $keyword(@exports){
- no strict 'refs';
- *{$into.'::'.$keyword} = $spec->{EXPORTS}{$keyword}
- || confess(qq{The $package package does not export "$keyword"});
- }
- }
- else{
- my $default = $spec->{DEFAULT};
- while(my($keyword, $code) = each %{$default}){
- no strict 'refs';
- *{$into.'::'.$keyword} = $code;
- }
- }
- return;
-}
-
-# the entity of general unimport()
-sub do_unimport {
- my($package, $arg) = @_;
-
- my $spec = $SPEC{$package}
- || confess("The package $package does not use Mouse::Exporter");
-
- my $from = _get_caller_package($arg);
-
- my $stash = do{
- no strict 'refs';
- \%{$from . '::'}
- };
-
- for my $keyword (@{ $spec->{REMOVABLES} }) {
- my $gv = \$stash->{$keyword};
- if(ref($gv) eq 'GLOB' && *{$gv}{CODE} == $spec->{EXPORTS}{$keyword}){ # make sure it is from us
- delete $stash->{$keyword};
- }
- }
- return;
-}
-
-# 1 extra level because it's called by import so there's a layer
-# of indirection
-sub _LEVEL(){ 1 }
-
-sub _get_caller_package {
- my($arg) = @_;
-
- if(ref $arg){
- return defined($arg->{into}) ? $arg->{into}
- : defined($arg->{into_level}) ? scalar caller(_LEVEL + $arg->{into_level})
- : scalar caller(_LEVEL);
- }
- else{
- return scalar caller(_LEVEL);
- }
-}
-
-#sub _spec{ %SPEC }
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse::Exporter - make an import() and unimport() just like Mouse.pm
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 SYNOPSIS
-
- package MyApp::Mouse;
-
- use Mouse ();
- use Mouse::Exporter;
-
- Mouse::Exporter->setup_import_methods(
- as_is => [ 'has_rw', 'other_sugar', \&Some::Random::thing ],
- also => 'Mouse',
- );
-
- sub has_rw {
- my $meta = caller->meta;
- my ( $name, %options ) = @_;
- $meta->add_attribute(
- $name,
- is => 'rw',
- %options,
- );
- }
-
- # then later ...
- package MyApp::User;
-
- use MyApp::Mouse;
-
- has 'name';
- has_rw 'size';
- thing;
-
- no MyApp::Mouse;
-
-=head1 DESCRIPTION
-
-This module encapsulates the exporting of sugar functions in a
-C<Mouse.pm>-like manner. It does this by building custom C<import>,
-C<unimport> methods for your module, based on a spec you provide.
-
-Note that C<Mouse::Exporter> does not provide the C<with_meta> option,
-but you can easily get the metaclass by C<< caller->meta >> as L</SYNOPSIS> shows.
-
-=head1 METHODS
-
-=head2 C<< setup_import_methods( ARGS ) >>
-
-=head2 C<< build_import_methods( ARGS ) -> (\&import, \&unimport) >>
-
-=head1 SEE ALSO
-
-L<Moose::Exporter>
-
-=cut
-
View
575 lib/Mouse/Meta/Attribute.pm
@@ -1,575 +0,0 @@
-package Mouse::Meta::Attribute;
-use Mouse::Util qw(:meta); # enables strict and warnings
-
-use Carp ();
-
-use Mouse::Meta::TypeConstraint;
-
-#use Mouse::Meta::Method::Accessor;
-use Mouse::Meta::Method::Delegation;
-
-sub _process_options{
- my($class, $name, $args) = @_;
-
-
- # XXX: for backward compatibility (with method modifiers)
- if($class->can('canonicalize_args') != \&canonicalize_args){
- %{$args} = $class->canonicalize_args($name, %{$args});
- }
-
- # taken from Class::MOP::Attribute::new
-
- defined($name)
- or $class->throw_error('You must provide a name for the attribute');
-
- if(!exists $args->{init_arg}){
- $args->{init_arg} = $name;
- }
-
- # 'required' requires eigher 'init_arg', 'builder', or 'default'
- my $can_be_required = defined( $args->{init_arg} );
-
- if(exists $args->{builder}){
- # XXX:
- # Moose refuses a CODE ref builder, but Mouse doesn't for backward compatibility
- # This feature will be changed in a future. (gfx)
- $class->throw_error('builder must be a defined scalar value which is a method name')
- #if ref $args->{builder} || !defined $args->{builder};
- if !defined $args->{builder};
-
- $can_be_required++;
- }
- elsif(exists $args->{default}){
- if(ref $args->{default} && ref($args->{default}) ne 'CODE'){
- $class->throw_error("References are not allowed as default values, you must "
- . "wrap the default of '$name' in a CODE reference (ex: sub { [] } and not [])");
- }
- $can_be_required++;
- }
-
- if( $args->{required} && !$can_be_required ) {
- $class->throw_error("You cannot have a required attribute ($name) without a default, builder, or an init_arg");
- }
-
- # taken from Mouse::Meta::Attribute->new and _process_args->
-
- if(exists $args->{is}){
- my $is = $args->{is};
-
- if($is eq 'ro'){
- $args->{reader} ||= $name;
- }
- elsif($is eq 'rw'){
- if(exists $args->{writer}){
- $args->{reader} ||= $name;
- }
- else{
- $args->{accessor} ||= $name;
- }
- }
- elsif($is eq 'bare'){
- # do nothing, but don't complain (later) about missing methods
- }
- else{
- $is = 'undef' if !defined $is;
- $class->throw_error("I do not understand this option (is => $is) on attribute ($name)");
- }
- }
-
- my $tc;
- if(exists $args->{isa}){
- $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args->{isa});
- }
- elsif(exists $args->{does}){
- $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_does_type_constraint($args->{does});
- }
- $tc = $args->{type_constraint};
-
- if($args->{coerce}){
- defined($tc)
- || $class->throw_error("You cannot have coercion without specifying a type constraint on attribute ($name)");
-
- $args->{weak_ref}
- && $class->throw_error("You cannot have a weak reference to a coerced value on attribute ($name)");
- }
-
- if ($args->{lazy_build}) {
- exists($args->{default})
- && $class->throw_error("You can not use lazy_build and default for the same attribute ($name)");
-
- $args->{lazy} = 1;
- $args->{builder} ||= "_build_${name}";
- if ($name =~ /^_/) {
- $args->{clearer} ||= "_clear${name}";
- $args->{predicate} ||= "_has${name}";
- }
- else {
- $args->{clearer} ||= "clear_${name}";
- $args->{predicate} ||= "has_${name}";
- }
- }
-
- if ($args->{auto_deref}) {
- defined($tc)
- || $class->throw_error("You cannot auto-dereference without specifying a type constraint on attribute ($name)");
-
- ( $tc->is_a_type_of('ArrayRef') || $tc->is_a_type_of('HashRef') )
- || $class->throw_error("You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)");
- }
-
- if (exists $args->{trigger}) {
- ('CODE' eq ref $args->{trigger})
- || $class->throw_error("Trigger must be a CODE ref on attribute ($name)");
- }
-
- if ($args->{lazy}) {
- (exists $args->{default} || defined $args->{builder})
- || $class->throw_error("You cannot have lazy attribute ($name) without specifying a default value for it");
- }
-
- return;
-}
-
-sub new {
- my $class = shift;
- my $name = shift;
-
- my %args = (@_ == 1) ? %{ $_[0] } : @_;
-
- $class->_process_options($name, \%args);
-
- $args{name} = $name;
-
- my $self = bless \%args, $class;
-
- # extra attributes
- if($class ne __PACKAGE__){
- $class->meta->_initialize_object($self, \%args);
- }
-
-# XXX: there is no fast way to check attribute validity
-# my @bad = ...;
-# if(@bad){
-# @bad = sort @bad;
-# Carp::cluck("Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad");
-# }
-
- return $self;
-}
-
-sub has_read_method { $_[0]->has_reader || $_[0]->has_accessor }
-sub has_write_method { $_[0]->has_writer || $_[0]->has_accessor }
-
-sub _create_args { # DEPRECATED
- $_[0]->{_create_args} = $_[1] if @_ > 1;
- $_[0]->{_create_args}
-}
-
-sub interpolate_class{
- my($class, $args) = @_;
-
- if(my $metaclass = delete $args->{metaclass}){
- $class = Mouse::Util::resolve_metaclass_alias( Attribute => $metaclass );
- }
-
- my @traits;
- if(my $traits_ref = delete $args->{traits}){
-
- for (my $i = 0; $i < @{$traits_ref}; $i++) {
- my $trait = Mouse::Util::resolve_metaclass_alias(Attribute => $traits_ref->[$i], trait => 1);
-
- next if $class->does($trait);
-
- push @traits, $trait;
-
- # are there options?
- push @traits, $traits_ref->[++$i]
- if ref($traits_ref->[$i+1]);
- }
-
- if (@traits) {
- $class = Mouse::Meta::Class->create_anon_class(
- superclasses => [ $class ],
- roles => \@traits,
- cache => 1,
- )->name;
- }
- }
-
- return( $class, @traits );
-}
-
-sub canonicalize_args{ # DEPRECATED
- my ($self, $name, %args) = @_;
-
- Carp::cluck("$self->canonicalize_args has been deprecated."
- . "Use \$self->_process_options instead.")
- if Mouse::Util::_MOUSE_VERBOSE;
-
- return %args;
-}
-
-sub create { # DEPRECATED
- my ($self, $class, $name, %args) = @_;
-
- Carp::cluck("$self->create has been deprecated."
- . "Use \$meta->add_attribute and \$attr->install_accessors instead.")
- if Mouse::Util::_MOUSE_VERBOSE;
-
- # noop
- return $self;
-}
-
-sub _coerce_and_verify {
- my($self, $value, $instance) = @_;
-
- my $type_constraint = $self->{type_constraint};
- return $value if !defined $type_constraint;
-
- if ($self->should_coerce && $type_constraint->has_coercion) {
- $value = $type_constraint->coerce($value);
- }
-
- $self->verify_against_type_constraint($value);
-
- return $value;
-}
-
-sub verify_against_type_constraint {
- my ($self, $value) = @_;
-
- my $type_constraint = $self->{type_constraint};
- return 1 if !$type_constraint;
- return 1 if $type_constraint->check($value);
-
- $self->verify_type_constraint_error($self->name, $value, $type_constraint);
-}
-
-sub verify_type_constraint_error {
- my($self, $name, $value, $type) = @_;
- $self->throw_error("Attribute ($name) does not pass the type constraint because: "
- . $type->get_message($value));
-}
-
-sub coerce_constraint { # DEPRECATED
- my $type = $_[0]->{type_constraint}
- or return $_[1];
-
- Carp::cluck("coerce_constraint() has been deprecated, which was an internal utility anyway");
-
- return Mouse::Util::TypeConstraints->typecast_constraints($_[0]->associated_class->name, $type, $_[1]);
-}
-
-sub clone_and_inherit_options{
- my($self, %args) = @_;
-
- my($attribute_class, @traits) = ref($self)->interpolate_class(\%args);
-
- $args{traits} = \@traits if @traits;
- # do not inherit the 'handles' attribute
- foreach my $name(keys %{$self}){
- if(!exists $args{$name} && $name ne 'handles'){
- $args{$name} = $self->{$name};
- }
- }
- return $attribute_class->new($self->name, %args);
-}
-
-sub clone_parent { # DEPRECATED
- my $self = shift;
- my $class = shift;
- my $name = shift;
- my %args = ($self->get_parent_args($class, $name), @_);
-
- Carp::cluck("$self->clone_parent has been deprecated."
- . "Use \$meta->add_attribute and \$attr->install_accessors instead.")
- if Mouse::Util::_MOUSE_VERBOSE;
-
- $self->clone_and_inherited_args($class, $name, %args);
-}
-
-sub get_parent_args { # DEPRECATED
- my $self = shift;
- my $class = shift;
- my $name = shift;
-
- for my $super ($class->linearized_isa) {
- my $super_attr = $super->can("meta") && $super->meta->get_attribute($name)
- or next;
- return %{ $super_attr->_create_args };
- }
-
- $self->throw_error("Could not find an attribute by the name of '$name' to inherit from");
-}
-
-
-sub get_read_method {
- $_[0]->reader || $_[0]->accessor
-}
-sub get_write_method {
- $_[0]->writer || $_[0]->accessor
-}
-
-sub get_read_method_ref{
- my($self) = @_;
-
- $self->{_read_method_ref} ||= do{
- my $metaclass = $self->associated_class
- or $self->throw_error('No asocciated class for ' . $self->name);
-
- my $reader = $self->{reader} || $self->{accessor};
- if($reader){
- $metaclass->name->can($reader);
- }
- else{
- $self->accessor_metaclass->_generate_reader($self, $metaclass);
- }
- };
-}
-
-sub get_write_method_ref{
- my($self) = @_;
-
- $self->{_write_method_ref} ||= do{
- my $metaclass = $self->associated_class
- or $self->throw_error('No asocciated class for ' . $self->name);
-
- my $reader = $self->{writer} || $self->{accessor};
- if($reader){
- $metaclass->name->can($reader);
- }
- else{
- $self->accessor_metaclass->_generate_writer($self, $metaclass);
- }
- };
-}
-
-sub _canonicalize_handles {
- my($self, $handles) = @_;
-
- if (ref($handles) eq 'HASH') {
- return %$handles;
- }
- elsif (ref($handles) eq 'ARRAY') {
- return map { $_ => $_ } @$handles;
- }
- elsif (ref($handles) eq 'Regexp') {
- my $class_or_role = ($self->{isa} || $self->{does})
- || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)");
-
- my $meta = Mouse::Meta::Class->initialize("$class_or_role"); # "" for stringify
- return map { $_ => $_ }
- grep { !Mouse::Object->can($_) && $_ =~ $handles }
- Mouse::Util::is_a_metarole($meta)
- ? $meta->get_method_list
- : $meta->get_all_method_names;
- }
- else {
- $self->throw_error("Unable to canonicalize the 'handles' option with $handles");
- }
-}
-
-sub associate_method{
- my ($attribute, $method_name) = @_;
- $attribute->{associated_methods}++;
- return;
-}
-
-sub delegation_metaclass() { 'Mouse::Meta::Method::Delegation' }
-
-sub install_accessors{
- my($attribute) = @_;
-
- my $metaclass = $attribute->associated_class;
- my $accessor_class = $attribute->accessor_metaclass;
-
- foreach my $type(qw(accessor reader writer predicate clearer)){
- if(exists $attribute->{$type}){
- my $generator = '_generate_' . $type;
- my $code = $accessor_class->$generator($attribute, $metaclass);
- $metaclass->add_method($attribute->{$type} => $code);
- $attribute->associate_method($attribute->{$type});
- }
- }
-
- # install delegation
- if(exists $attribute->{handles}){
- my $delegation_class = $attribute->delegation_metaclass;
- my %handles = $attribute->_canonicalize_handles($attribute->{handles});
- my $reader = $attribute->get_read_method_ref;
-
- while(my($handle_name, $method_to_call) = each %handles){
- my $code = $delegation_class->_generate_delegation($attribute, $metaclass,
- $reader, $handle_name, $method_to_call);
-
- $metaclass->add_method($handle_name => $code);
- $attribute->associate_method($handle_name);
- }
- }
-
- if($attribute->can('create') != \&create){
- # backword compatibility
- $attribute->create($metaclass, $attribute->name, %{$attribute});
- }
-
- return;
-}
-
-sub throw_error{
- my $self = shift;
-
- my $metaclass = (ref $self && $self->associated_class) || 'Mouse::Meta::Class';
- $metaclass->throw_error(@_, depth => 1);
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse::Meta::Attribute - The Mouse attribute metaclass
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 METHODS
-
-=head2 C<< new(%options) -> Mouse::Meta::Attribute >>
-
-Instantiates a new Mouse::Meta::Attribute. Does nothing else.
-
-It adds the following options to the constructor:
-
-=over 4
-
-=item C<< is => 'ro', 'rw', 'bare' >>
-
-This provides a shorthand for specifying the C<reader>, C<writer>, or
-C<accessor> names. If the attribute is read-only ('ro') then it will
-have a C<reader> method with the same attribute as the name.
-
-If it is read-write ('rw') then it will have an C<accessor> method
-with the same name. If you provide an explicit C<writer> for a
-read-write attribute, then you will have a C<reader> with the same
-name as the attribute, and a C<writer> with the name you provided.
-
-Use 'bare' when you are deliberately not installing any methods
-(accessor, reader, etc.) associated with this attribute; otherwise,
-Moose will issue a deprecation warning when this attribute is added to a
-metaclass.
-
-=item C<< isa => Type >>
-
-This option accepts a type. The type can be a string, which should be
-a type name. If the type name is unknown, it is assumed to be a class
-name.
-
-This option can also accept a L<Moose::Meta::TypeConstraint> object.
-
-If you I<also> provide a C<does> option, then your C<isa> option must
-be a class name, and that class must do the role specified with
-C<does>.
-
-=item C<< does => Role >>
-
-This is short-hand for saying that the attribute's type must be an
-object which does the named role.
-
-B<This option is not yet supported.>
-
-=item C<< coerce => Bool >>
-
-This option is only valid for objects with a type constraint
-(C<isa>). If this is true, then coercions will be applied whenever
-this attribute is set.
-
-You can make both this and the C<weak_ref> option true.
-
-=item C<< trigger => CodeRef >>
-
-This option accepts a subroutine reference, which will be called after
-the attribute is set.
-
-=item C<< required => Bool >>
-
-An attribute which is required must be provided to the constructor. An
-attribute which is required can also have a C<default> or C<builder>,
-which will satisfy its required-ness.
-
-A required attribute must have a C<default>, C<builder> or a
-non-C<undef> C<init_arg>
-
-=item C<< lazy => Bool >>
-
-A lazy attribute must have a C<default> or C<builder>. When an
-attribute is lazy, the default value will not be calculated until the
-attribute is read.
-
-=item C<< weak_ref => Bool >>
-
-If this is true, the attribute's value will be stored as a weak
-reference.
-
-=item C<< auto_deref => Bool >>
-
-If this is true, then the reader will dereference the value when it is
-called. The attribute must have a type constraint which defines the
-attribute as an array or hash reference.
-
-=item C<< lazy_build => Bool >>
-
-Setting this to true makes the attribute lazy and provides a number of
-default methods.
-
- has 'size' => (
- is => 'ro',
- lazy_build => 1,
- );
-
-is equivalent to this:
-
- has 'size' => (
- is => 'ro',
- lazy => 1,
- builder => '_build_size',
- clearer => 'clear_size',
- predicate => 'has_size',
- );
-
-=back
-
-=head2 C<< associate_method(MethodName) >>
-
-Associates a method with the attribute. Typically, this is called internally
-when an attribute generates its accessors.
-
-Currently the argument I<MethodName> is ignored in Mouse.
-
-=head2 C<< verify_against_type_constraint(Item) -> TRUE | ERROR >>
-
-Checks that the given value passes this attribute's type constraint. Returns C<true>
-on success, otherwise C<confess>es.
-
-=head2 C<< clone_and_inherit_options(options) -> Mouse::Meta::Attribute >>
-
-Creates a new attribute in the owner class, inheriting options from parent classes.
-Accessors and helper methods are installed. Some error checking is done.
-
-=head2 C<< get_read_method_ref >>
-
-=head2 C<< get_write_method_ref >>
-
-Returns the subroutine reference of a method suitable for reading or
-writing the attribute's value in the associated class. These methods
-always return a subroutine reference, regardless of whether or not the
-attribute is read- or write-only.
-
-=head1 SEE ALSO
-
-L<Moose::Meta::Attribute>
-
-L<Class::MOP::Attribute>
-
-=cut
-
View
553 lib/Mouse/Meta/Class.pm
@@ -1,553 +0,0 @@
-package Mouse::Meta::Class;
-use Mouse::Util qw/:meta get_linear_isa not_supported/; # enables strict and warnings
-
-use Scalar::Util qw/blessed weaken/;
-
-use Mouse::Meta::Module;
-our @ISA = qw(Mouse::Meta::Module);
-
-sub attribute_metaclass;
-sub method_metaclass;
-
-sub constructor_class;
-sub destructor_class;
-
-my @MetaClassTypes = qw(
- attribute_metaclass
- method_metaclass
- constructor_class
- destructor_class
-);
-
-sub _construct_meta {
- my($class, %args) = @_;
-
- $args{attributes} = {};
- $args{methods} = {};
- $args{roles} = [];
-
- $args{superclasses} = do {
- no strict 'refs';
- \@{ $args{package} . '::ISA' };
- };
-
- my $self = bless \%args, ref($class) || $class;
- if(ref($self) ne __PACKAGE__){
- $self->meta->_initialize_object($self, \%args);
- }
- return $self;
-}
-
-sub create_anon_class{
- my $self = shift;
- return $self->create(undef, @_);
-}
-
-sub is_anon_class;
-
-sub roles;
-
-sub calculate_all_roles {
- my $self = shift;
- my %seen;
- return grep { !$seen{ $_->name }++ }
- map { $_->calculate_all_roles } @{ $self->roles };
-}
-
-sub superclasses {
- my $self = shift;
-
- if (@_) {
- foreach my $super(@_){
- Mouse::Util::load_class($super);
- my $meta = Mouse::Util::get_metaclass_by_name($super);
-
- next if not defined $meta;
-
- if(Mouse::Util::is_a_metarole($meta)){
- $self->throw_error("You cannot inherit from a Mouse Role ($super)");
- }
-
- next if $self->isa(ref $meta); # _superclass_meta_is_compatible
-
- $self->_reconcile_with_superclass_meta($meta);
- }
- @{ $self->{superclasses} } = @_;
- }
-
- return @{ $self->{superclasses} };
-}
-
-sub _reconcile_with_superclass_meta {
- my($self, $super_meta) = @_;
-
- my @incompatibles;
-
- foreach my $metaclass_type(@MetaClassTypes){
- my $super_c = $super_meta->$metaclass_type();
- my $self_c = $self->$metaclass_type();
-
- if(!$super_c->isa($self_c)){
- push @incompatibles, ($metaclass_type => $super_c);
- }
- }
-
- my @roles;
-
- foreach my $role($self->meta->calculate_all_roles){
- if(!$super_meta->meta->does_role($role->name)){
- push @roles, $role->name;
- }
- }
-
- #print "reconcile($self vs. $super_meta; @roles; @incompatibles)\n";
-
- require Mouse::Util::MetaRole;
- Mouse::Util::MetaRole::apply_metaclass_roles(
- for_class => $self,
- metaclass => ref $super_meta,
- metaclass_roles => \@roles,
- @incompatibles,
- );
- return;
-}
-
-sub find_method_by_name{
- my($self, $method_name) = @_;
- defined($method_name)
- or $self->throw_error('You must define a method name to find');
-
- foreach my $class( $self->linearized_isa ){
- my $method = $self->initialize($class)->get_method($method_name);
- return $method if defined $method;
- }
- return undef;
-}
-
-sub get_all_methods {
- my($self) = @_;
- return map{ $self->find_method_by_name($_) } $self->get_all_method_names;
-}
-
-sub get_all_method_names {
- my $self = shift;
- my %uniq;
- return grep { $uniq{$_}++ == 0 }
- map { Mouse::Meta::Class->initialize($_)->get_method_list() }
- $self->linearized_isa;
-}
-
-sub find_attribute_by_name{
- my($self, $name) = @_;
- my $attr;
- foreach my $class($self->linearized_isa){
- my $meta = Mouse::Util::get_metaclass_by_name($class) or next;
- $attr = $meta->get_attribute($name) and last;
- }
- return $attr;
-}
-
-sub add_attribute {
- my $self = shift;
-
- my($attr, $name);
-
- if(blessed $_[0]){
- $attr = $_[0];
-
- $attr->isa('Mouse::Meta::Attribute')
- || $self->throw_error("Your attribute must be an instance of Mouse::Meta::Attribute (or a subclass)");
-
- $name = $attr->name;
- }
- else{
- # _process_attribute
- $name = shift;
-
- my %args = (@_ == 1) ? %{$_[0]} : @_;
-
- defined($name)
- or $self->throw_error('You must provide a name for the attribute');
-
- if ($name =~ s/^\+//) { # inherited attributes
- my $inherited_attr = $self->find_attribute_by_name($name)
- or $self->throw_error("Could not find an attribute by the name of '$name' to inherit from in ".$self->name);
-
- $attr = $inherited_attr->clone_and_inherit_options(%args);
- }
- else{
- my($attribute_class, @traits) = $self->attribute_metaclass->interpolate_class(\%args);
- $args{traits} = \@traits if @traits;
-
- $attr = $attribute_class->new($name, %args);
- }
- }
-
- weaken( $attr->{associated_class} = $self );
-
- $self->{attributes}{$attr->name} = $attr;
- $attr->install_accessors();
-
- if(Mouse::Util::_MOUSE_VERBOSE && !$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){
- Carp::cluck(qq{Attribute (}.$attr->name.qq{) of class }.$self->name.qq{ has no associated methods (did you mean to provide an "is" argument?)});
- }
- return $attr;
-}
-
-sub compute_all_applicable_attributes {
- Carp::cluck('compute_all_applicable_attributes() has been deprecated')
- if Mouse::Util::_MOUSE_VERBOSE;
- return shift->get_all_attributes(@_)
-}
-
-sub linearized_isa;
-
-sub new_object;
-
-sub clone_object {
- my $class = shift;
- my $object = shift;
- my %params = (@_ == 1) ? %{$_[0]} : @_;
-
- (blessed($object) && $object->isa($class->name))
- || $class->throw_error("You must pass an instance of the metaclass (" . $class->name . "), not ($object)");
-
- my $cloned = bless { %$object }, ref $object;
- $class->_initialize_object($cloned, \%params);
-
- return $cloned;
-}
-
-sub clone_instance {
- my ($class, $instance, %params) = @_;
-
- Carp::cluck('clone_instance has been deprecated. Use clone_object instead')
- if Mouse::Util::_MOUSE_VERBOSE;
- return $class->clone_object($instance, %params);
-}
-
-
-sub immutable_options {
- my ( $self, @args ) = @_;
-
- return (
- inline_constructor => 1,
- inline_destructor => 1,
- constructor_name => 'new',
- @args,
- );
-}
-
-
-sub make_immutable {
- my $self = shift;
- my %args = $self->immutable_options(@_);
-
- $self->{is_immutable}++;
-
- if ($args{inline_constructor}) {
- my $c = $self->constructor_class;
- Mouse::Util::load_class($c);
- $self->add_method($args{constructor_name} =>
- $c->_generate_constructor($self, \%args));
- }
-
- if ($args{inline_destructor}) {
- my $c = $self->destructor_class;
- Mouse::Util::load_class($c);
- $self->add_method(DESTROY =>
- $c->_generate_destructor($self, \%args));
- }
-
- # Moose's make_immutable returns true allowing calling code to skip setting an explicit true value
- # at the end of a source file.
- return 1;
-}
-
-sub make_mutable { not_supported }
-
-sub is_immutable { $_[0]->{is_immutable} }
-sub is_mutable { !$_[0]->{is_immutable} }
-
-sub _install_modifier_pp{
- my( $self, $type, $name, $code ) = @_;
- my $into = $self->name;
-
- my $original = $into->can($name)
- or $self->throw_error("The method '$name' is not found in the inheritance hierarchy for class $into");
-
- my $modifier_table = $self->{modifiers}{$name};
-
- if(!$modifier_table){
- my(@before, @after, @around, $cache, $modified);
-
- $cache = $original;
-
- $modified = sub {
- for my $c (@before) { $c->(@_) }
-
- if(wantarray){ # list context
- my @rval = $cache->(@_);
-
- for my $c(@after){ $c->(@_) }
- return @rval;
- }
- elsif(defined wantarray){ # scalar context
- my $rval = $cache->(@_);
-
- for my $c(@after){ $c->(@_) }
- return $rval;
- }
- else{ # void context
- $cache->(@_);
-
- for my $c(@after){ $c->(@_) }
- return;
- }
- };
-
- $self->{modifiers}{$name} = $modifier_table = {
- original => $original,
-
- before => \@before,
- after => \@after,
- around => \@around,
-
- cache => \$cache, # cache for around modifiers
- };
-
- $self->add_method($name => $modified);
- }
-
- if($type eq 'before'){
- unshift @{$modifier_table->{before}}, $code;
- }
- elsif($type eq 'after'){
- push @{$modifier_table->{after}}, $code;
- }
- else{ # around
- push @{$modifier_table->{around}}, $code;
-
- my $next = ${ $modifier_table->{cache} };
- ${ $modifier_table->{cache} } = sub{ $code->($next, @_) };
- }
-
- return;
-}
-
-sub _install_modifier {
- my ( $self, $type, $name, $code ) = @_;
-
- # load Class::Method::Modifiers first
- my $no_cmm_fast = do{
- local $@;
- eval q{ require Class::Method::Modifiers::Fast };
- $@;
- };
-
- my $impl;
- if($no_cmm_fast){
- $impl = \&_install_modifier_pp;
- }
- else{
- my $install_modifier = Class::Method::Modifiers::Fast->can('_install_modifier');
- $impl = sub {
- my ( $self, $type, $name, $code ) = @_;
- my $into = $self->name;
- $install_modifier->($into, $type, $name, $code);
-
- $self->add_method($name => do{
- no strict 'refs';
- \&{ $into . '::' . $name };
- });
- return;
- };
- }
-
- # replace this method itself :)
- {
- no warnings 'redefine';
- *_install_modifier = $impl;
- }
-
- $self->$impl( $type, $name, $code );
-}
-
-sub add_before_method_modifier {
- my ( $self, $name, $code ) = @_;
- $self->_install_modifier( 'before', $name, $code );
-}
-
-sub add_around_method_modifier {
- my ( $self, $name, $code ) = @_;
- $self->_install_modifier( 'around', $name, $code );
-}
-
-sub add_after_method_modifier {
- my ( $self, $name, $code ) = @_;
- $self->_install_modifier( 'after', $name, $code );
-}
-
-sub add_override_method_modifier {
- my ($self, $name, $code) = @_;
-
- if($self->has_method($name)){
- $self->throw_error("Cannot add an override method if a local method is already present");
- }
-
- my $package = $self->name;
-
- my $super_body = $package->can($name)
- or $self->throw_error("You cannot override '$name' because it has no super method");
-
- $self->add_method($name => sub {
- local $Mouse::SUPER_PACKAGE = $package;
- local $Mouse::SUPER_BODY = $super_body;
- local @Mouse::SUPER_ARGS = @_;
-
- $code->(@_);
- });
- return;
-}
-
-sub add_augment_method_modifier {
- my ($self, $name, $code) = @_;
- if($self->has_method($name)){
- $self->throw_error("Cannot add an augment method if a local method is already present");
- }
-
- my $super = $self->find_method_by_name($name)
- or $self->throw_error("You cannot augment '$name' because it has no super method");
-
- my $super_package = $super->package_name;
- my $super_body = $super->body;
-
- $self->add_method($name => sub{
- local $Mouse::INNER_BODY{$super_package} = $code;
- local $Mouse::INNER_ARGS{$super_package} = [@_];
- $super_body->(@_);
- });
- return;
-}
-
-sub does_role {
- my ($self, $role_name) = @_;
-
- (defined $role_name)
- || $self->throw_error("You must supply a role name to look for");
-
- for my $class ($self->linearized_isa) {
- my $meta = Mouse::Util::get_metaclass_by_name($class)
- or next;
-
- for my $role (@{ $meta->roles }) {
-
- return 1 if $role->does_role($role_name);
- }
- }
-
- return 0;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse::Meta::Class - The Mouse class metaclass
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 METHODS
-
-=head2 C<< initialize(ClassName) -> Mouse::Meta::Class >>
-
-Finds or creates a C<Mouse::Meta::Class> instance for the given ClassName. Only
-one instance should exist for a given class.
-
-=head2 C<< name -> ClassName >>
-
-Returns the name of the owner class.
-
-=head2 C<< superclasses -> ClassNames >> C<< superclass(ClassNames) >>
-
-Gets (or sets) the list of superclasses of the owner class.
-
-=head2 C<< add_method(name => CodeRef) >>
-
-Adds a method to the owner class.
-
-=head2 C<< has_method(name) -> Bool >>
-
-Returns whether we have a method with the given name.
-
-=head2 C<< get_method(name) -> Mouse::Meta::Method | undef >>
-
-Returns a L<Mouse::Meta::Method> with the given name.
-
-Note that you can also use C<< $metaclass->name->can($name) >> for a method body.
-
-=head2 C<< get_method_list -> Names >>
-
-Returns a list of method names which are defined in the local class.
-If you want a list of all applicable methods for a class, use the
-C<get_all_methods> method.
-
-=head2 C<< get_all_methods -> (Mouse::Meta::Method) >>
-
-Return the list of all L<Mouse::Meta::Method> instances associated with
-the class and its superclasses.
-
-=head2 C<< add_attribute(name => spec | Mouse::Meta::Attribute) >>
-
-Begins keeping track of the existing L<Mouse::Meta::Attribute> for the owner
-class.
-
-=head2 C<< has_attribute(Name) -> Bool >>
-
-Returns whether we have a L<Mouse::Meta::Attribute> with the given name.
-
-=head2 C<< get_attribute Name -> Mouse::Meta::Attribute | undef >>
-
-Returns the L<Mouse::Meta::Attribute> with the given name.
-
-=head2 C<< get_attribute_list -> Names >>
-
-Returns a list of attribute names which are defined in the local
-class. If you want a list of all applicable attributes for a class,
-use the C<get_all_attributes> method.
-
-=head2 C<< get_all_attributes -> (Mouse::Meta::Attribute) >>
-
-Returns the list of all L<Mouse::Meta::Attribute> instances associated with
-this class and its superclasses.
-
-=head2 C<< linearized_isa -> [ClassNames] >>
-
-Returns the list of classes in method dispatch order, with duplicates removed.
-
-=head2 C<< new_object(Parameters) -> Instance >>
-
-Creates a new instance.
-
-=head2 C<< clone_object(Instance, Parameters) -> Instance >>
-
-Clones the given instance which must be an instance governed by this
-metaclass.
-
-=head2 C<< throw_error(Message, Parameters) >>
-
-Throws an error with the given message.
-
-=head1 SEE ALSO
-
-L<Mouse::Meta::Module>
-
-L<Moose::Meta::Class>
-
-L<Class::MOP::Class>
-
-=cut
-
View
52 lib/Mouse/Meta/Method.pm
@@ -1,52 +0,0 @@
-package Mouse::Meta::Method;
-use Mouse::Util qw(:meta); # enables strict and warnings
-
-use overload
- '&{}' => sub{ $_[0]->body },
- fallback => 1,
-;
-
-sub wrap{
- my $class = shift;
-
- return $class->_new(@_);
-}
-
-sub _new{
- my($class, %args) = @_;
- my $self = bless \%args, $class;
-
- if($class ne __PACKAGE__){
- $self->meta->_initialize_object($self, \%args);
- }
- return $self;
-}
-
-sub body { $_[0]->{body} }
-sub name { $_[0]->{name} }
-sub package_name { $_[0]->{package} }
-sub associated_metaclass { $_[0]->{associated_metaclass} }
-
-sub fully_qualified_name {
- my($self) = @_;
- return $self->package_name . '::' . $self->name;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse::Meta::Method - A Mouse Method metaclass
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 SEE ALSO
-
-L<Moose::Meta::Method>
-
-L<Class::MOP::Method>
-
-=cut
View
185 lib/Mouse/Meta/Method/Accessor.pm
@@ -1,185 +0,0 @@
-package Mouse::Meta::Method::Accessor;
-use Mouse::Util qw(:meta); # enables strict and warnings
-
-sub _inline_slot{
- my(undef, $self_var, $attr_name) = @_;
- return sprintf '%s->{q{%s}}', $self_var, $attr_name;
-}
-
-sub _generate_accessor_any{
- my($method_class, $type, $attribute, $class) = @_;
-
- my $name = $attribute->name;
- my $default = $attribute->default;
- my $constraint = $attribute->type_constraint;
- my $builder = $attribute->builder;
- my $trigger = $attribute->trigger;
- my $is_weak = $attribute->is_weak_ref;
- my $should_deref = $attribute->should_auto_deref;
- my $should_coerce = (defined($constraint) && $constraint->has_coercion && $attribute->should_coerce);
-
- my $compiled_type_constraint = defined($constraint) ? $constraint->_compiled_type_constraint : undef;
-
- my $self = '$_[0]';
- my $slot = $method_class->_inline_slot($self, $name);;
-
- my $accessor = sprintf(qq{package %s;\n#line 1 "%s for %s (%s)"\n}, $class->name, $type, $name, __FILE__)
- . "sub {\n";
-
- if ($type eq 'rw' || $type eq 'wo') {
- if($type eq 'rw'){
- $accessor .=
- 'if (scalar(@_) >= 2) {' . "\n";
- }
- else{ # writer
- $accessor .=
- 'if(@_ < 2){ Carp::confess("Not enough arguments for the writer of '.$name.'") }'.
- '{' . "\n";
- }
-
- my $value = '$_[1]';
-
- if (defined $constraint) {
- if ($should_coerce) {
- $accessor .=
- "\n".
- 'my $val = $constraint->coerce('.$value.');';
- $value = '$val';
- }
- $accessor .=
- "\n".
- '$compiled_type_constraint->('.$value.') or
- $attribute->verify_type_constraint_error($name, '.$value.', $constraint);' . "\n";
- }
-
- # if there's nothing left to do for the attribute we can return during
- # this setter
- $accessor .= 'return ' if !$is_weak && !$trigger && !$should_deref;
-
- $accessor .= "$slot = $value;\n";
-
- if ($is_weak) {
- $accessor .= "Scalar::Util::weaken($slot) if ref $slot;\n";
- }
-
- if ($trigger) {
- $accessor .= '$trigger->('.$self.', '.$value.');' . "\n";
- }
-
- $accessor .= "}\n";
- }
- elsif($type eq 'ro') {
- $accessor .= 'Carp::confess("Cannot assign a value to a read-only accessor") if scalar(@_) >= 2;' . "\n";
- }
- else{
- $class->throw_error("Unknown accessor type '$type'");
- }
-
- if ($attribute->is_lazy) {
- my $value;
-
- if (defined $builder){
- $value = "$self->\$builder()";
- }
- elsif (ref($default) eq 'CODE'){
- $value = "$self->\$default()";
- }
- else{
- $value = '$default';
- }
-
- $accessor .= "if(!exists $slot){\n";
- if($should_coerce){
- $accessor .= "$slot = \$constraint->coerce($value)";
- }
- elsif(defined $constraint){
- $accessor .= "my \$tmp = $value;\n";
-
- $accessor .= "\$compiled_type_constraint->(\$tmp)";
- $accessor .= " || \$attribute->verify_type_constraint_error(\$name, \$tmp, \$constraint);\n";
- $accessor .= "$slot = \$tmp;\n";
- }
- else{
- $accessor .= "$slot = $value;\n";
- }
- if ($is_weak) {
- $accessor .= "Scalar::Util::weaken($slot) if ref $slot;\n";
- }
- $accessor .= "}\n";
- }
-
- if ($should_deref) {
- if ($constraint->is_a_type_of('ArrayRef')) {
- $accessor .= "return \@{ $slot || [] } if wantarray;\n";
- }
- elsif($constraint->is_a_type_of('HashRef')){
- $accessor .= "return \%{ $slot || {} } if wantarray;\n";
- }
- else{
- $class->throw_error("Can not auto de-reference the type constraint " . $constraint->name);
- }
- }
-
- $accessor .= "return $slot;\n}\n";
-
- #print $accessor, "\n";
- my $code;
- my $e = do{
- local $@;
- $code = eval $accessor;
- $@;
- };
- die $e if $e;
-
- return $code;
-}
-
-sub _generate_accessor{
- my $class = shift;
- return $class->_generate_accessor_any(rw => @_);
-}
-
-sub _generate_reader {
- my $class = shift;
- return $class->_generate_accessor_any(ro => @_);
-}
-
-sub _generate_writer {
- my $class = shift;
- return $class->_generate_accessor_any(wo => @_);
-}
-
-sub _generate_predicate {
- my (undef, $attribute, $class) = @_;
-
- my $slot = $attribute->name;
- return sub{
- return exists $_[0]->{$slot};
- };
-}
-
-sub _generate_clearer {
- my (undef, $attribute, $class) = @_;
-
- my $slot = $attribute->name;
- return sub{
- delete $_[0]->{$slot};
- };
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Mouse::Meta::Method::Accessor - A Mouse method generator for accessors
-
-=head1 VERSION
-
-This document describes Mouse version 0.42
-
-=head1 SEE ALSO
-
-L<Moose::Meta::Method::Accessor>
-
-=cut
View
206 lib/Mouse/Meta/Method/Constructor.pm
@@ -1,206 +0,0 @@
-package Mouse::Meta::Method::Constructor;
-use Mouse::Util qw(:meta); # enables strict and warnings
-
-sub _inline_slot{
- my(undef, $self_var, $attr_name) = @_;
- return sprintf '%s->{q{%s}}', $self_var, $attr_name;
-}
-
-sub _generate_constructor {
- my ($class, $metaclass, $args) = @_;
-
- my $associated_metaclass_name = $metaclass->name;
-
- my @attrs = $metaclass->get_all_attributes;
-
- my $buildall = $class->_generate_BUILDALL($metaclass);
- my $buildargs = $class->_generate_BUILDARGS($metaclass);
- my $processattrs = $class->_generate_processattrs($metaclass, \@attrs);
-
- my @checks = map { $_ && $_->_compiled_type_constraint }
- map { $_->type_constraint } @attrs;
-
- my $source = sprintf("#line %d %s\n", __LINE__, __FILE__).<<"...";
- sub \{
- my \$class = shift;
- return \$class->Mouse::Object::new(\@_)
- if \$class ne q{$associated_metaclass_name};
- # BUILDARGS
- $buildargs;
- my \$instance = bless {}, \$class;
- # process attributes
- $processattrs;
- # BUILDALL
- $buildall;
- return \$instance;
- }
-...
- #warn $source;
- my $code;
- my $e = do{
- local $@;
- $code = eval $source;
- $@;
- };
- die $e if $e;
- return $code;
-}
-
-sub _generate_processattrs {
- my ($method_class, $metaclass, $attrs) = @_;
- my @res;
-
- my $has_triggers;
-
- for my $index (0 .. @$attrs - 1) {
- my $code = '';
-
- my $attr = $attrs->[$index];
- my $key = $attr->name;
-
- my $init_arg = $attr->init_arg;
- my $type_constraint = $attr->type_constraint;
- my $is_weak_ref = $attr->is_weak_ref;
- my $need_coercion;
-
- my $instance_slot = $method_class->_inline_slot('$instance', $key);
- my $attr_var = "\$attrs[$index]";
- my $constraint_var;
-
- if(defined $type_constraint){
- $constraint_var = "$attr_var\->{type_constraint}";
- $need_coercion = ($attr->should_coerce && $type_constraint->has_coercion);
- }
-
- $code .= "# initialize $key\n";
-
- my $post_process = '';
- if(defined $type_constraint){
- $post_process .= "\$checks[$index]->($instance_slot)";
- $post_process .= " or $attr_var->verify_type_constraint_error(q{$key}, $instance_slot, $constraint_var);\n";
- }
- if($is_weak_ref){
- $post_process .= "Scalar::Util::weaken($instance_slot) if ref $instance_slot;\n";
- }
-
- if (defined $init_arg) {
- my $value = "\$args->{q{$init_arg}}";
-
- $code .= "if (exists $value) {\n";
-
</