r73862 - in /branches/upstream/libmoosex-nonmoose-perl/current: ./ lib/MooseX/ lib/MooseX/NonMoose/ lib/MooseX/NonMoose/Meta/Role/ t/
carnil at users.alioth.debian.org
carnil at users.alioth.debian.org
Sat Apr 30 19:44:59 UTC 2011
Author: carnil
Date: Sat Apr 30 19:44:47 2011
New Revision: 73862
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=73862
Log:
[svn-upgrade] new version libmoosex-nonmoose-perl (0.21)
Added:
branches/upstream/libmoosex-nonmoose-perl/current/t/11-constructor-name.t
Modified:
branches/upstream/libmoosex-nonmoose-perl/current/Changes
branches/upstream/libmoosex-nonmoose-perl/current/MANIFEST
branches/upstream/libmoosex-nonmoose-perl/current/META.json
branches/upstream/libmoosex-nonmoose-perl/current/META.yml
branches/upstream/libmoosex-nonmoose-perl/current/Makefile.PL
branches/upstream/libmoosex-nonmoose-perl/current/README
branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose.pm
branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/InsideOut.pm
branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Class.pm
branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
branches/upstream/libmoosex-nonmoose-perl/current/t/00-compile.t
branches/upstream/libmoosex-nonmoose-perl/current/t/26-no-new-constructor-error.t
Modified: branches/upstream/libmoosex-nonmoose-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/Changes?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/Changes (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/Changes Sat Apr 30 19:44:47 2011
@@ -1,4 +1,14 @@
Revision history for MooseX-NonMoose
+
+0.21 2011-04-29
+ - Allow this module to work with constructors with names other than
+ 'new'. If you're extending a class with a constructor named something
+ other than 'new', you should declare this when calling extends, as in:
+
+ extends 'Foo' => { -constructor_name => 'create' };
+
+ This will ensure that calling 'create' will also call Moose's
+ constructor.
0.20 2011-03-22
- fix warning when passing inline_constructor => 0 with no superclass new
Modified: branches/upstream/libmoosex-nonmoose-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/MANIFEST?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/MANIFEST (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/MANIFEST Sat Apr 30 19:44:47 2011
@@ -19,6 +19,7 @@
t/06-disable.t
t/07-extends-moose-object.t
t/10-immutable.t
+t/11-constructor-name.t
t/20-BUILD.t
t/21-BUILDARGS.t
t/22-replaced-constructor.t
Modified: branches/upstream/libmoosex-nonmoose-perl/current/META.json
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/META.json?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/META.json (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/META.json Sat Apr 30 19:44:47 2011
@@ -4,7 +4,7 @@
"Jesse Luehrs <doy at tozt dot net>"
],
"dynamic_config" : 0,
- "generated_by" : "Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.110580",
+ "generated_by" : "Dist::Zilla version 4.200006, CPAN::Meta::Converter version 2.101670",
"license" : [
"perl_5"
],
@@ -16,7 +16,7 @@
"prereqs" : {
"configure" : {
"requires" : {
- "ExtUtils::MakeMaker" : "6.31"
+ "ExtUtils::MakeMaker" : "6.30"
}
},
"runtime" : {
@@ -40,7 +40,7 @@
"web" : "http://github.com/doy/moosex-nonmoose"
}
},
- "version" : "0.20",
+ "version" : "0.21",
"x_Dist_Zilla" : {
"plugins" : [
{
@@ -52,87 +52,87 @@
}
},
"name" : "@DOY/TestMoreDoneTesting",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::GatherDir",
"name" : "@DOY/GatherDir",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::PruneCruft",
"name" : "@DOY/PruneCruft",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::ManifestSkip",
"name" : "@DOY/ManifestSkip",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::MetaYAML",
"name" : "@DOY/MetaYAML",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::License",
"name" : "@DOY/License",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::Readme",
"name" : "@DOY/Readme",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::ExtraTests",
"name" : "@DOY/ExtraTests",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::ExecDir",
"name" : "@DOY/ExecDir",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::ShareDir",
"name" : "@DOY/ShareDir",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::MakeMaker",
"name" : "@DOY/MakeMaker",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::Manifest",
"name" : "@DOY/Manifest",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::TestRelease",
"name" : "@DOY/TestRelease",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::ConfirmRelease",
"name" : "@DOY/ConfirmRelease",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::MetaConfig",
"name" : "@DOY/MetaConfig",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::MetaJSON",
"name" : "@DOY/MetaJSON",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::NextRelease",
"name" : "@DOY/NextRelease",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::CheckChangesHasContent",
@@ -142,17 +142,17 @@
{
"class" : "Dist::Zilla::Plugin::PkgVersion",
"name" : "@DOY/PkgVersion",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::PodCoverageTests",
"name" : "@DOY/PodCoverageTests",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::PodSyntaxTests",
"name" : "@DOY/PodSyntaxTests",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::NoTabsTests",
@@ -167,37 +167,37 @@
{
"class" : "Dist::Zilla::Plugin::CompileTests",
"name" : "@DOY/CompileTests",
- "version" : "1.103030"
+ "version" : "1.101800"
},
{
"class" : "Dist::Zilla::Plugin::Repository",
"name" : "@DOY/Repository",
- "version" : "0.17"
+ "version" : "0.18"
},
{
"class" : "Dist::Zilla::Plugin::Git::Check",
"name" : "@DOY/Git::Check",
- "version" : "1.110500"
+ "version" : "1.110330"
},
{
"class" : "Dist::Zilla::Plugin::Git::Tag",
"name" : "@DOY/Git::Tag",
- "version" : "1.110500"
+ "version" : "1.110330"
},
{
"class" : "Dist::Zilla::Plugin::Git::NextVersion",
"name" : "@DOY/Git::NextVersion",
- "version" : "1.110500"
+ "version" : "1.110330"
},
{
"class" : "Dist::Zilla::Plugin::PodWeaver",
"name" : "@DOY/PodWeaver",
- "version" : "3.101641"
+ "version" : "3.101640"
},
{
"class" : "Dist::Zilla::Plugin::UploadToCPAN",
"name" : "@DOY/UploadToCPAN",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
@@ -208,7 +208,7 @@
}
},
"name" : "Prereqs",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
@@ -219,27 +219,37 @@
}
},
"name" : "TestRequires",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":InstallModules",
- "version" : "4.200004"
+ "version" : "4.200006"
+ },
+ {
+ "class" : "Dist::Zilla::Plugin::FinderCode",
+ "name" : ":IncModules",
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":TestFiles",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":ExecFiles",
- "version" : "4.200004"
+ "version" : "4.200006"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":ShareFiles",
- "version" : "4.200004"
+ "version" : "4.200006"
+ },
+ {
+ "class" : "Dist::Zilla::Plugin::FinderCode",
+ "name" : ":MainModule",
+ "version" : "4.200006"
}
],
"zilla" : {
@@ -247,7 +257,7 @@
"config" : {
"is_trial" : 0
},
- "version" : "4.200004"
+ "version" : "4.200006"
}
}
}
Modified: branches/upstream/libmoosex-nonmoose-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/META.yml?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/META.yml (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/META.yml Sat Apr 30 19:44:47 2011
@@ -6,9 +6,9 @@
Test::Fatal: 0
Test::More: 0.88
configure_requires:
- ExtUtils::MakeMaker: 6.31
+ ExtUtils::MakeMaker: 6.30
dynamic_config: 0
-generated_by: 'Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.110580'
+generated_by: 'Dist::Zilla version 4.200006, CPAN::Meta::Converter version 2.101670'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -19,7 +19,7 @@
Moose: 1.15
resources:
repository: git://github.com/doy/moosex-nonmoose.git
-version: 0.20
+version: 0.21
x_Dist_Zilla:
plugins:
-
@@ -29,71 +29,71 @@
phase: test
type: requires
name: '@DOY/TestMoreDoneTesting'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::GatherDir
name: '@DOY/GatherDir'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::PruneCruft
name: '@DOY/PruneCruft'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::ManifestSkip
name: '@DOY/ManifestSkip'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::MetaYAML
name: '@DOY/MetaYAML'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::License
name: '@DOY/License'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::Readme
name: '@DOY/Readme'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::ExtraTests
name: '@DOY/ExtraTests'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::ExecDir
name: '@DOY/ExecDir'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::ShareDir
name: '@DOY/ShareDir'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::MakeMaker
name: '@DOY/MakeMaker'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::Manifest
name: '@DOY/Manifest'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::TestRelease
name: '@DOY/TestRelease'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::ConfirmRelease
name: '@DOY/ConfirmRelease'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::MetaConfig
name: '@DOY/MetaConfig'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::MetaJSON
name: '@DOY/MetaJSON'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::NextRelease
name: '@DOY/NextRelease'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::CheckChangesHasContent
name: '@DOY/CheckChangesHasContent'
@@ -101,15 +101,15 @@
-
class: Dist::Zilla::Plugin::PkgVersion
name: '@DOY/PkgVersion'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::PodCoverageTests
name: '@DOY/PodCoverageTests'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::PodSyntaxTests
name: '@DOY/PodSyntaxTests'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::NoTabsTests
name: '@DOY/NoTabsTests'
@@ -121,31 +121,31 @@
-
class: Dist::Zilla::Plugin::CompileTests
name: '@DOY/CompileTests'
- version: 1.103030
+ version: 1.101800
-
class: Dist::Zilla::Plugin::Repository
name: '@DOY/Repository'
- version: 0.17
+ version: 0.18
-
class: Dist::Zilla::Plugin::Git::Check
name: '@DOY/Git::Check'
- version: 1.110500
+ version: 1.110330
-
class: Dist::Zilla::Plugin::Git::Tag
name: '@DOY/Git::Tag'
- version: 1.110500
+ version: 1.110330
-
class: Dist::Zilla::Plugin::Git::NextVersion
name: '@DOY/Git::NextVersion'
- version: 1.110500
+ version: 1.110330
-
class: Dist::Zilla::Plugin::PodWeaver
name: '@DOY/PodWeaver'
- version: 3.101641
+ version: 3.101640
-
class: Dist::Zilla::Plugin::UploadToCPAN
name: '@DOY/UploadToCPAN'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::Prereqs
config:
@@ -153,7 +153,7 @@
phase: runtime
type: requires
name: Prereqs
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::Prereqs
config:
@@ -161,25 +161,33 @@
phase: test
type: requires
name: TestRequires
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::FinderCode
name: ':InstallModules'
- version: 4.200004
+ version: 4.200006
+ -
+ class: Dist::Zilla::Plugin::FinderCode
+ name: ':IncModules'
+ version: 4.200006
-
class: Dist::Zilla::Plugin::FinderCode
name: ':TestFiles'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::FinderCode
name: ':ExecFiles'
- version: 4.200004
+ version: 4.200006
-
class: Dist::Zilla::Plugin::FinderCode
name: ':ShareFiles'
- version: 4.200004
+ version: 4.200006
+ -
+ class: Dist::Zilla::Plugin::FinderCode
+ name: ':MainModule'
+ version: 4.200006
zilla:
class: Dist::Zilla::Dist::Builder
config:
is_trial: 0
- version: 4.200004
+ version: 4.200006
Modified: branches/upstream/libmoosex-nonmoose-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/Makefile.PL?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/Makefile.PL (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/Makefile.PL Sat Apr 30 19:44:47 2011
@@ -4,7 +4,7 @@
-use ExtUtils::MakeMaker 6.31;
+use ExtUtils::MakeMaker 6.30;
@@ -16,7 +16,7 @@
'Test::More' => '0.88'
},
'CONFIGURE_REQUIRES' => {
- 'ExtUtils::MakeMaker' => '6.31'
+ 'ExtUtils::MakeMaker' => '6.30'
},
'DISTNAME' => 'MooseX-NonMoose',
'EXE_FILES' => [],
@@ -26,7 +26,7 @@
'List::MoreUtils' => '0',
'Moose' => '1.15'
},
- 'VERSION' => '0.20',
+ 'VERSION' => '0.21',
'test' => {
'TESTS' => 't/*.t'
}
Modified: branches/upstream/libmoosex-nonmoose-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/README?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/README (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/README Sat Apr 30 19:44:47 2011
@@ -1,7 +1,7 @@
This archive contains the distribution MooseX-NonMoose,
-version 0.20:
+version 0.21:
easy subclassing of non-Moose classes
Modified: branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose.pm?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose.pm (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose.pm Sat Apr 30 19:44:47 2011
@@ -1,6 +1,6 @@
package MooseX::NonMoose;
BEGIN {
- $MooseX::NonMoose::VERSION = '0.20';
+ $MooseX::NonMoose::VERSION = '0.21';
}
use Moose::Exporter;
# ABSTRACT: easy subclassing of non-Moose classes
@@ -35,7 +35,7 @@
=head1 VERSION
-version 0.20
+version 0.21
=head1 SYNOPSIS
@@ -97,13 +97,14 @@
C<MooseX::NonMoose> to support superclasses whose constructors would get
confused by the extra arguments that Moose requires (for attributes, etc.)
-=head1 TODO
+Not all non-Moose classes use C<new> as the name of their constructor. This
+module allows you to extend these classes by explicitly stating which method is
+the constructor, during the call to C<extends>. The syntax looks like this:
-=over 4
+ extends 'Foo' => { -constructor_name => 'create' };
-=item * Allow for constructors with names other than C<new>.
-
-=back
+similar to how you can already pass C<-version> in the C<extends> call in a
+similar way.
=head1 BUGS/CAVEATS
@@ -122,10 +123,6 @@
although using method modifiers on the constructor should work identically to
normal Moose classes.
-=item * C<MooseX::NonMoose> currently assumes in several places that the
-superclass constructor will be called C<new>. This may be made configurable
-in the future.
-
=back
Please report any bugs through RT: email
@@ -138,7 +135,7 @@
=over 4
-=item * L<Moose::Cookbook::FAQ/How do I make non-Moose constructors work with Moose?>
+=item * L<Moose::Manual::FAQ/How do I make non-Moose constructors work with Moose?>
=item * L<MooseX::Alien>
Modified: branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/InsideOut.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/InsideOut.pm?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/InsideOut.pm (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/InsideOut.pm Sat Apr 30 19:44:47 2011
@@ -1,6 +1,6 @@
package MooseX::NonMoose::InsideOut;
BEGIN {
- $MooseX::NonMoose::InsideOut::VERSION = '0.20';
+ $MooseX::NonMoose::InsideOut::VERSION = '0.21';
}
use Moose::Exporter;
# ABSTRACT: easy subclassing of non-Moose non-hashref classes
@@ -36,7 +36,7 @@
=head1 VERSION
-version 0.20
+version 0.21
=head1 SYNOPSIS
Modified: branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Class.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Class.pm?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Class.pm (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Class.pm Sat Apr 30 19:44:47 2011
@@ -1,6 +1,6 @@
package MooseX::NonMoose::Meta::Role::Class;
BEGIN {
- $MooseX::NonMoose::Meta::Role::Class::VERSION = '0.20';
+ $MooseX::NonMoose::Meta::Role::Class::VERSION = '0.21';
}
use Moose::Role;
use List::MoreUtils qw(any);
@@ -17,6 +17,14 @@
is => 'rw',
isa => 'Bool',
default => 0,
+);
+
+# overrides the constructor_name attr that already exists
+has constructor_name => (
+ is => 'rw',
+ isa => 'Str',
+ lazy => 1,
+ default => sub { shift->throw_error("No constructor name has been set") },
);
sub _determine_constructor_options {
@@ -34,12 +42,13 @@
my %options = @options;
return @options if !$options{inline_constructor};
- # XXX: get constructor name from the constructor metaclass?
- my $local_constructor = $self->get_method('new');
+ my $constructor_name = $self->constructor_name;
+
+ my $local_constructor = $self->get_method($constructor_name);
if (!defined($local_constructor)) {
warn "Not inlining a constructor for " . $self->name . " since "
. "its parent " . ($self->superclasses)[0] . " doesn't contain a "
- . "'new' method. "
+ . "constructor named '$constructor_name'. "
. "If you are certain you don't need to inline your"
. " constructor, specify inline_constructor => 0 in your"
. " call to " . $self->name . "->meta->make_immutable\n";
@@ -88,13 +97,12 @@
# if the current class defined a custom new method (since subs happen at
# BEGIN time), don't try to override it
- return if $self->has_method('new');
+ return if $self->has_method($self->constructor_name);
# we need to get the non-moose constructor from the superclass
# of the class where this method actually exists, regardless of what class
# we're calling it on
- # XXX: get constructor name from the constructor metaclass?
- my $super_new = $self->find_next_method_by_name('new');
+ my $super_new = $self->find_next_method_by_name($self->constructor_name);
# if we're trying to extend a (non-immutable) moose class, just do nothing
return if $super_new->package_name eq 'Moose::Object';
@@ -115,7 +123,7 @@
$super_new->associated_metaclass->_inlined_methods;
}
- $self->add_method(new => sub {
+ $self->add_method($self->constructor_name => sub {
my $class = shift;
my $params = $class->BUILDARGS(@_);
@@ -200,6 +208,46 @@
my $self = shift;
return $self->$orig unless @_;
+
+ # XXX lots of duplication between here and MMC::superclasses
+ my ($constructor_name, $constructor_class);
+ for my $super (@{ Data::OptList::mkopt(\@_) }) {
+ my ($name, $opts) = @{ $super };
+
+ my $cur_constructor_name = delete $opts->{'-constructor_name'};
+
+ if (defined($constructor_name) && defined($cur_constructor_name)) {
+ $self->throw_error(
+ "You have already specified "
+ . "${constructor_class}::${constructor_name} as the parent "
+ . "constructor; ${name}::${cur_constructor_name} cannot also be "
+ . "the constructor"
+ );
+ }
+
+ Class::MOP::load_class($name, $opts);
+
+ if (defined($cur_constructor_name)) {
+ my $meta = Class::MOP::class_of($name);
+ $self->throw_error(
+ "You specified '$cur_constructor_name' as the constructor for "
+ . "$name, but $name has no method by that name"
+ ) unless $meta
+ ? $meta->find_method_by_name($cur_constructor_name)
+ : $name->can($cur_constructor_name);
+ }
+
+ if (!defined($constructor_name)) {
+ $constructor_name = $cur_constructor_name;
+ $constructor_class = $name;
+ }
+
+ delete $opts->{'-constructor_name'};
+ }
+
+ $self->constructor_name(
+ defined($constructor_name) ? $constructor_name : 'new'
+ );
my @superclasses = @_;
push @superclasses, 'Moose::Object'
@@ -292,7 +340,7 @@
=head1 VERSION
-version 0.20
+version 0.21
=head1 SYNOPSIS
Modified: branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Constructor.pm?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Constructor.pm (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/lib/MooseX/NonMoose/Meta/Role/Constructor.pm Sat Apr 30 19:44:47 2011
@@ -1,6 +1,6 @@
package MooseX::NonMoose::Meta::Role::Constructor;
BEGIN {
- $MooseX::NonMoose::Meta::Role::Constructor::VERSION = '0.20';
+ $MooseX::NonMoose::Meta::Role::Constructor::VERSION = '0.21';
}
use Moose::Role;
# ABSTRACT: constructor method trait for L<MooseX::NonMoose>
@@ -88,7 +88,7 @@
=head1 VERSION
-version 0.20
+version 0.21
=head1 SYNOPSIS
Modified: branches/upstream/libmoosex-nonmoose-perl/current/t/00-compile.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/t/00-compile.t?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/t/00-compile.t (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/t/00-compile.t Sat Apr 30 19:44:47 2011
@@ -4,9 +4,6 @@
use warnings;
use Test::More;
-
-
-
use File::Find;
use File::Temp qw{ tempdir };
Added: branches/upstream/libmoosex-nonmoose-perl/current/t/11-constructor-name.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/t/11-constructor-name.t?rev=73862&op=file
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/t/11-constructor-name.t (added)
+++ branches/upstream/libmoosex-nonmoose-perl/current/t/11-constructor-name.t Sat Apr 30 19:44:47 2011
@@ -1,0 +1,108 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+use Test::Moose;
+
+{
+ package Foo;
+
+ sub create {
+ my $class = shift;
+ my %params = @_;
+ bless { foo => ($params{foo} || 'FOO') }, $class;
+ }
+
+ sub foo { shift->{foo} }
+}
+
+{
+ package Foo::Sub;
+ use Moose;
+ use MooseX::NonMoose;
+
+ extends 'Foo' => { -constructor_name => 'create' };
+
+ has bar => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'BAR',
+ );
+}
+
+with_immutable {
+ my $foo = Foo::Sub->create;
+ is($foo->foo, 'FOO', "nonmoose constructor called");
+ is($foo->bar, 'BAR', "moose constructor called");
+} 'Foo::Sub';
+
+{
+ package Foo::BadSub;
+ use Moose;
+ use MooseX::NonMoose;
+
+ ::like(
+ ::exception {
+ extends 'Foo' => { -constructor_name => 'something_else' };
+ },
+ qr/You specified 'something_else' as the constructor for Foo, but Foo has no method by that name/,
+ "specifying an incorrect constructor name dies"
+ );
+}
+
+{
+ package Foo::Mixin;
+
+ sub thing {
+ return shift->foo . 'BAZ';
+ }
+}
+
+{
+ package Foo::Sub2;
+ use Moose;
+ use MooseX::NonMoose;
+
+ extends 'Foo::Mixin', 'Foo' => { -constructor_name => 'create' };
+
+ has bar => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'BAR',
+ );
+}
+
+with_immutable {
+ my $foo = Foo::Sub2->create;
+ is($foo->foo, 'FOO', "nonmoose constructor called");
+ is($foo->bar, 'BAR', "moose constructor called");
+ is($foo->thing, 'FOOBAZ', "mixin still works");
+} 'Foo::Sub2';
+
+{
+ package Bar;
+
+ sub make {
+ my $class = shift;
+ my %params = @_;
+ bless { baz => ($params{baz} || 'BAZ') }, $class;
+ }
+}
+
+{
+ package Foo::Bar::Sub;
+ use Moose;
+ use MooseX::NonMoose;
+
+ ::like(
+ ::exception {
+ extends 'Bar' => { -constructor_name => 'make' },
+ 'Foo' => { -constructor_name => 'create' };
+ },
+ qr/You have already specified Bar::make as the parent constructor; Foo::create cannot also be the constructor/,
+ "can't specify two parent constructors"
+ );
+}
+
+done_testing;
Modified: branches/upstream/libmoosex-nonmoose-perl/current/t/26-no-new-constructor-error.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-nonmoose-perl/current/t/26-no-new-constructor-error.t?rev=73862&op=diff
==============================================================================
--- branches/upstream/libmoosex-nonmoose-perl/current/t/26-no-new-constructor-error.t (original)
+++ branches/upstream/libmoosex-nonmoose-perl/current/t/26-no-new-constructor-error.t Sat Apr 30 19:44:47 2011
@@ -18,8 +18,11 @@
my $warning;
local $SIG{__WARN__} = sub { $warning = $_[0] };
__PACKAGE__->meta->make_immutable;
- ::like($warning, qr/Not inlining.*doesn't contain a 'new' method/,
- "warning when trying to make_immutable without a superclass 'new'");
+ ::like(
+ $warning,
+ qr/Not inlining.*doesn't contain a constructor named 'new'/,
+ "warning when trying to make_immutable without a superclass 'new'"
+ );
}
}
More information about the Pkg-perl-cvs-commits
mailing list