r20469 - in /branches/upstream/libmoosex-strictconstructor-perl: ./ current/ current/lib/ current/lib/MooseX/ current/lib/MooseX/Object/ current/lib/MooseX/StrictConstructor/ current/lib/MooseX/StrictConstructor/Meta/ current/lib/MooseX/StrictConstructor/Meta/Method/ current/t/

antgel-guest at users.alioth.debian.org antgel-guest at users.alioth.debian.org
Wed May 28 14:17:15 UTC 2008


Author: antgel-guest
Date: Wed May 28 14:17:15 2008
New Revision: 20469

URL: http://svn.debian.org/wsvn/?sc=1&rev=20469
Log:
[svn-inject] Installing original source of libmoosex-strictconstructor-perl

Added:
    branches/upstream/libmoosex-strictconstructor-perl/
    branches/upstream/libmoosex-strictconstructor-perl/current/
    branches/upstream/libmoosex-strictconstructor-perl/current/Build.PL
    branches/upstream/libmoosex-strictconstructor-perl/current/Changes
    branches/upstream/libmoosex-strictconstructor-perl/current/MANIFEST
    branches/upstream/libmoosex-strictconstructor-perl/current/META.yml
    branches/upstream/libmoosex-strictconstructor-perl/current/Makefile.PL
    branches/upstream/libmoosex-strictconstructor-perl/current/README
    branches/upstream/libmoosex-strictconstructor-perl/current/SIGNATURE
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/StrictConstructor.pm
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor.pm
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Class.pm
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/
    branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm
    branches/upstream/libmoosex-strictconstructor-perl/current/t/
    branches/upstream/libmoosex-strictconstructor-perl/current/t/basic.t
    branches/upstream/libmoosex-strictconstructor-perl/current/t/perlcritic.t
    branches/upstream/libmoosex-strictconstructor-perl/current/t/pod-coverage.t
    branches/upstream/libmoosex-strictconstructor-perl/current/t/pod.t

Added: branches/upstream/libmoosex-strictconstructor-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/Build.PL?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/Build.PL (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/Build.PL Wed May 28 14:17:15 2008
@@ -1,0 +1,19 @@
+use strict;
+use warnings;
+
+require 5.00601;
+
+use Module::Build;
+
+my $builder = Module::Build->new
+    ( module_name        => 'MooseX::StrictConstructor',
+      license            => 'perl',
+      requires           => { 'Moose'      => 0.26,
+                              'Test::More' => 0,
+                            },
+      create_makefile_pl => 'passthrough',
+      create_readme      => 1,
+      sign               => 1,
+    );
+
+$builder->create_build_script();

Added: branches/upstream/libmoosex-strictconstructor-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/Changes?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/Changes (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/Changes Wed May 28 14:17:15 2008
@@ -1,0 +1,27 @@
+0.05   2008-04-18
+
+- The fix in 0.04 only worked for non-immutable classes.
+
+
+0.04   2008-04-18
+
+- This module did not respect the init_arg attribute setting, and used
+  the attribute name instead. Reported by Matt Trout. RT #34507.
+
+
+0.03   2007-11-20
+
+- Require Moose 0.26, since that's first version to offer init_meta(),
+  apparently.
+
+
+0.02   2007-11-15
+
+- Moose was missing from the prereq list. Reported by Slaven Rezic.
+
+- Version 0.01 did not work after a class was made immutable.
+
+
+0.01   2007-11-14
+
+- First version, released on an unsuspecting world.

Added: branches/upstream/libmoosex-strictconstructor-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/MANIFEST?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/MANIFEST (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/MANIFEST Wed May 28 14:17:15 2008
@@ -1,0 +1,15 @@
+Build.PL
+Changes
+lib/MooseX/Object/StrictConstructor.pm
+lib/MooseX/StrictConstructor.pm
+lib/MooseX/StrictConstructor/Meta/Class.pm
+lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+README
+t/basic.t
+t/perlcritic.t
+t/pod-coverage.t
+t/pod.t
+SIGNATURE    Added here by Module::Build

Added: branches/upstream/libmoosex-strictconstructor-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/META.yml?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/META.yml (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/META.yml Wed May 28 14:17:15 2008
@@ -1,0 +1,26 @@
+---
+name: MooseX-StrictConstructor
+version: 0.05
+author:
+  - 'Dave Rolsky, C<< <autarch at urth.org> >>'
+abstract: Make your object constructors blow up on unknown attributes
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+requires:
+  Moose: 0.26
+  Test::More: 0
+provides:
+  MooseX::Object::StrictConstructor:
+    file: lib/MooseX/Object/StrictConstructor.pm
+  MooseX::StrictConstructor:
+    file: lib/MooseX/StrictConstructor.pm
+    version: 0.05
+  MooseX::StrictConstructor::Meta::Class:
+    file: lib/MooseX/StrictConstructor/Meta/Class.pm
+  MooseX::StrictConstructor::Meta::Method::Constructor:
+    file: lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm
+generated_by: Module::Build version 0.2808
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.2.html
+  version: 1.2

Added: branches/upstream/libmoosex-strictconstructor-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/Makefile.PL?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/Makefile.PL (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/Makefile.PL Wed May 28 14:17:15 2008
@@ -1,0 +1,31 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
+    
+    unless (eval "use Module::Build::Compat 0.02; 1" ) {
+      print "This module requires Module::Build to install itself.\n";
+      
+      require ExtUtils::MakeMaker;
+      my $yn = ExtUtils::MakeMaker::prompt
+	('  Install Module::Build now from CPAN?', 'y');
+      
+      unless ($yn =~ /^y/i) {
+	die " *** Cannot install without Module::Build.  Exiting ...\n";
+      }
+      
+      require Cwd;
+      require File::Spec;
+      require CPAN;
+      
+      # Save this 'cause CPAN will chdir all over the place.
+      my $cwd = Cwd::cwd();
+      
+      CPAN::Shell->install('Module::Build::Compat');
+      CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
+	or die "Couldn't install Module::Build, giving up.\n";
+      
+      chdir $cwd or die "Cannot chdir() back to $cwd: $!";
+    }
+    eval "use Module::Build::Compat 0.02; 1" or die $@;
+    
+    Module::Build::Compat->run_build_pl(args => \@ARGV);
+    require Module::Build;
+    Module::Build::Compat->write_makefile(build_class => 'Module::Build');

Added: branches/upstream/libmoosex-strictconstructor-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/README?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/README (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/README Wed May 28 14:17:15 2008
@@ -1,0 +1,63 @@
+NAME
+    MooseX::StrictConstructor - Make your object constructors blow up on
+    unknown attributes
+
+SYNOPSIS
+        package My::Class;
+
+        use MooseX::StrictConstructor; # instead of use Moose
+
+        has 'size' => ...;
+
+        # then later ...
+
+        # this blows up because color is not a known attribute
+        My::Class->new( size => 5, color => 'blue' );
+
+DESCRIPTION
+    Using this class to load Moose instead of just loading using Moose
+    itself makes your constructors "strict". If your constructor is called
+    with an attribute init argument that your class does not declare, then
+    it calls "Carp::confess()". This is a great way to catch small typos.
+
+  Subverting Strictness
+    You may find yourself wanting to accept a parameter to the constructor
+    that is not the name of an attribute.
+
+    In that case, you'll probably be writing a "BUILD()" method to deal with
+    it. Your "BUILD()" method will receive two parameters, the new object,
+    and a hash reference of parameters passed to the constructor.
+
+    If you delete keys from this hash reference, then they will not be seen
+    when this class does its checking.
+
+      sub BUILD {
+          my $self   = shift;
+          my $params = shift;
+
+          if ( delete $params->{do_something} ) {
+              ...
+          }
+      }
+
+  Caveats
+    Using this class replaces the default Moose meta class,
+    "Moose::Meta::Class", with its own,
+    "MooseX::StrictConstructor::Meta::Class". If you have your own meta
+    class, this distro will probably not work for you.
+
+AUTHOR
+    Dave Rolsky, "<autarch at urth.org>"
+
+BUGS
+    Please report any bugs or feature requests to
+    "bug-moosex-strictconstructor at rt.cpan.org", or through the web interface
+    at <http://rt.cpan.org>. I will be notified, and then you'll
+    automatically be notified of progress on your bug as I make changes.
+
+COPYRIGHT & LICENSE
+    Copyright 2007 Dave Rolsky, All Rights Reserved.
+
+    This program is free software; you can redistribute it and/or modify it
+    under the same terms as Perl itself.
+

Added: branches/upstream/libmoosex-strictconstructor-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/SIGNATURE?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/SIGNATURE (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/SIGNATURE Wed May 28 14:17:15 2008
@@ -1,0 +1,37 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.55.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 c064e5eeef39c4434b8460e64f71ba90a8ef5bf2 Build.PL
+SHA1 762950b1def80e885b31560773fe7bd4772be751 Changes
+SHA1 cda8df304bf3b8a67747fb5fcd97dccb32370008 MANIFEST
+SHA1 6b201af91e674ddc204095a6c54df56393b0621c META.yml
+SHA1 cd14ada78fb37a0d926edd86eddcdf7f939de582 Makefile.PL
+SHA1 6e146058a15cd4170066c830ca5f3eac68b146bc README
+SHA1 2db66fdcf07316150b3981351c22f492da0af4fc lib/MooseX/Object/StrictConstructor.pm
+SHA1 5dd99f311f2d0542990496a728056cb76113634d lib/MooseX/StrictConstructor.pm
+SHA1 812fcb248e74ec3415c2e7d50af6cac7974e76f8 lib/MooseX/StrictConstructor/Meta/Class.pm
+SHA1 5d16960ec2ef53791c6f66b9daf97a929e902b5a lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm
+SHA1 ee75031bb26f217880d77c04b3e43690da74473f t/basic.t
+SHA1 98c875c39bedc57bc3c52b583ddc866c6d184d0a t/perlcritic.t
+SHA1 28a931f3b0c075d8d6c4ce47d5e89c3fdb19ed0f t/pod-coverage.t
+SHA1 cec881e89926d320475f9de2b7fad02c2169f510 t/pod.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFICWsK3Or3ZzQuifMRAqKsAJ9qBULoLZKRCXr0kiwZ1aYOEM84XACg6Kph
+z+ygE8cBnoIPdnLZOPqDmCI=
+=sfg4
+-----END PGP SIGNATURE-----

Added: branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/StrictConstructor.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/StrictConstructor.pm?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/StrictConstructor.pm (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/Object/StrictConstructor.pm Wed May 28 14:17:15 2008
@@ -1,0 +1,65 @@
+package MooseX::Object::StrictConstructor;
+
+use strict;
+use warnings;
+
+use Moose;
+
+use Carp 'confess';
+
+use metaclass 'MooseX::StrictConstructor::Meta::Class';
+
+
+extends 'Moose::Object';
+
+after 'BUILDALL' => sub
+{
+    my $self   = shift;
+    my $params = shift;
+
+    my %attrs =
+        ( map { $_ => 1 }
+          grep { defined }
+          map { $_->init_arg() }
+          $self->meta()->compute_all_applicable_attributes()
+        );
+
+    my @bad = sort grep { ! $attrs{$_} }  keys %{ $params };
+
+    if (@bad)
+    {
+        confess "Found unknown attribute(s) init_arg passed to the constructor: @bad";
+    }
+
+    return;
+};
+
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::Object::StrictConstructor - Implements strict constructors as a Moose::Object subclass
+
+=head1 DESCRIPTION
+
+This class has no external interface. When you use
+C<MooseX::StrictConstructor>, your objects will subclass this class
+rather than Moose::Object.
+
+=head1 AUTHOR
+
+Dave Rolsky, C<< <autarch at urth.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Dave Rolsky, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut

Added: branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor.pm?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor.pm (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor.pm Wed May 28 14:17:15 2008
@@ -1,0 +1,107 @@
+package MooseX::StrictConstructor;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.05';
+
+use Moose;
+use MooseX::Object::StrictConstructor;
+
+
+sub import
+{
+    my $caller = caller();
+
+    return if $caller eq 'main';
+
+    Moose::init_meta( $caller,
+                      'MooseX::Object::StrictConstructor',
+                      'MooseX::StrictConstructor::Meta::Class',
+                    );
+
+    Moose->import( { into => $caller } );
+
+    return;
+}
+
+
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::StrictConstructor - Make your object constructors blow up on unknown attributes
+
+=head1 SYNOPSIS
+
+    package My::Class;
+
+    use MooseX::StrictConstructor; # instead of use Moose
+
+    has 'size' => ...;
+
+    # then later ...
+
+    # this blows up because color is not a known attribute
+    My::Class->new( size => 5, color => 'blue' );
+
+=head1 DESCRIPTION
+
+Using this class to load Moose instead of just loading using Moose
+itself makes your constructors "strict". If your constructor is called
+with an attribute init argument that your class does not declare, then
+it calls "Carp::confess()". This is a great way to catch small typos.
+
+=head2 Subverting Strictness
+
+You may find yourself wanting to accept a parameter to the constructor
+that is not the name of an attribute.
+
+In that case, you'll probably be writing a C<BUILD()> method to deal
+with it. Your C<BUILD()> method will receive two parameters, the new
+object, and a hash reference of parameters passed to the constructor.
+
+If you delete keys from this hash reference, then they will not be
+seen when this class does its checking.
+
+  sub BUILD {
+      my $self   = shift;
+      my $params = shift;
+
+      if ( delete $params->{do_something} ) {
+          ...
+      }
+  }
+
+=head2 Caveats
+
+Using this class replaces the default Moose meta class,
+C<Moose::Meta::Class>, with its own,
+C<MooseX::StrictConstructor::Meta::Class>. If you have your own meta
+class, this distro will probably not work for you.
+
+=head1 AUTHOR
+
+Dave Rolsky, C<< <autarch at urth.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-moosex-strictconstructor at rt.cpan.org>, or through the web
+interface at L<http://rt.cpan.org>.  I will be notified, and then
+you'll automatically be notified of progress on your bug as I make
+changes.
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Dave Rolsky, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut

Added: branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Class.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Class.pm?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Class.pm (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Class.pm Wed May 28 14:17:15 2008
@@ -1,0 +1,61 @@
+package MooseX::StrictConstructor::Meta::Class;
+
+use strict;
+use warnings;
+
+use MooseX::StrictConstructor::Meta::Method::Constructor;
+
+use Moose;
+
+extends 'Moose::Meta::Class';
+
+around 'make_immutable' => sub ## no critic RequireArgUnpacking
+{
+    my $orig = shift;
+    my $self = shift;
+
+    return
+        $self->$orig
+            ( constructor_class => 'MooseX::StrictConstructor::Meta::Method::Constructor',
+              @_,
+            );
+};
+
+no Moose;
+
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::StrictConstructor::Meta::Class - A meta class for classes with strict constructors
+
+=head1 SYNOPSIS
+
+  use MooseX::StrictConstructor;
+
+=head1 DESCRIPTION
+
+This class simply overrides C<make_immutable()> in
+C<Moose::Meta::Class> to use
+C<MooseX::StrictConstructor::Meta::Method::Constructor> as the
+constructor class.
+
+You should never have to use this class directly.
+
+=head1 AUTHOR
+
+Dave Rolsky, C<< <autarch at urth.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Dave Rolsky, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut

Added: branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/lib/MooseX/StrictConstructor/Meta/Method/Constructor.pm Wed May 28 14:17:15 2008
@@ -1,0 +1,75 @@
+package MooseX::StrictConstructor::Meta::Method::Constructor;
+
+use strict;
+use warnings;
+
+use Carp ();
+use Moose;
+
+extends 'Moose::Meta::Method::Constructor';
+
+override '_generate_BUILDALL' => sub ## no critic RequireArgUnpacking
+{
+    my $self = shift;
+
+    my $source = super();
+    $source .= ";\n" if $source;
+
+    my @attrs =
+        ( map { "$_ => 1," }
+          grep { defined }
+          map { $_->init_arg() }
+          @{ $self->attributes() }
+        );
+
+    $source .= <<"EOF";
+my \%attrs = (@attrs);
+
+my \@bad = sort grep { ! \$attrs{\$_} }  keys \%params;
+
+if (\@bad) {
+    Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
+}
+EOF
+
+    return $source;
+};
+
+no Moose;
+
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::StrictConstructor::Meta::Method::Constructor - A meta class to make immutable constructors strict
+
+=head1 SYNOPSIS
+
+  use MooseX::StrictConstructor;
+
+=head1 DESCRIPTION
+
+This class simply overrides C<_generate_BUILDALL()> in
+C<Moose::Meta::Method::Constructor> so that classes that are made
+immutable have a strict constructor.
+
+You should never have to use this class directly.
+
+=head1 AUTHOR
+
+Dave Rolsky, C<< <autarch at urth.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Dave Rolsky, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+

Added: branches/upstream/libmoosex-strictconstructor-perl/current/t/basic.t
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/t/basic.t?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/t/basic.t (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/t/basic.t Wed May 28 14:17:15 2008
@@ -1,0 +1,153 @@
+use strict;
+use warnings;
+
+use Test::More tests => 15;
+
+
+{
+    package Standard;
+
+    use Moose;
+
+    has 'thing' => ( is => 'rw' );
+}
+
+{
+    package Stricter;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw' );
+}
+
+{
+    package Subclass;
+
+    use MooseX::StrictConstructor;
+
+    extends 'Stricter';
+
+    has 'size' => ( is => 'rw' );
+}
+
+{
+    package Tricky;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw' );
+
+    sub BUILD
+    {
+        my $self   = shift;
+        my $params = shift;
+
+        delete $params->{spy};
+    }
+}
+
+{
+    package InitArg;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw', 'init_arg' => 'other' );
+    has 'size'  => ( is => 'rw', 'init_arg' => undef );
+}
+
+{
+    package ImmutableInitArg;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw', 'init_arg' => 'other' );
+    has 'size'  => ( is => 'rw', 'init_arg' => undef );
+
+    no Moose;
+    __PACKAGE__->meta()->make_immutable();
+}
+
+{
+    package Immutable;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw' );
+
+    no Moose;
+    __PACKAGE__->meta()->make_immutable();
+}
+
+{
+    package ImmutableTricky;
+
+    use MooseX::StrictConstructor;
+
+    has 'thing' => ( is => 'rw' );
+
+    sub BUILD
+    {
+        my $self   = shift;
+        my $params = shift;
+
+        delete $params->{spy};
+    }
+
+    no Moose;
+    __PACKAGE__->meta()->make_immutable();
+}
+
+
+eval { Standard->new( thing => 1, bad => 99 ) };
+is( $@, '', 'standard Moose class ignores unknown params' );
+
+eval { Stricter->new( thing => 1, bad => 99 ) };
+like( $@, qr/unknown attribute.+: bad/, 'strict constructor blows up on unknown params' );
+
+eval { Subclass->new( thing => 1, size => 'large' ) };
+is( $@, '', 'subclass constructor handles known attributes correctly' );
+
+eval { Tricky->new( thing => 1, spy => 99 ) };
+is( $@, '', 'can work around strict constructor by deleting params in BUILD()' );
+
+eval { Tricky->new( thing => 1, agent => 99 ) };
+like( $@, qr/unknown attribute.+: agent/, 'Tricky still blows up on unknown params other than spy' );
+
+eval { Subclass->new( thing => 1, bad => 99 ) };
+like( $@, qr/unknown attribute.+: bad/, 'subclass constructor blows up on unknown params' );
+
+eval { InitArg->new( thing => 1 ) };
+like( $@, qr/unknown attribute.+: thing/,
+      'InitArg blows up with attribute name' );
+
+eval { InitArg->new( size => 1 ) };
+like( $@, qr/unknown attribute.+: size/,
+      'InitArg blows up when given attribute with undef init_arg' );
+
+eval { InitArg->new( other => 1 ) };
+is( $@, '',
+    'InitArg works when given proper init_arg' );
+
+eval { ImmutableInitArg->new( thing => 1 ) };
+like( $@, qr/unknown attribute.+: thing/,
+      'ImmutableInitArg blows up with attribute name' );
+
+eval { ImmutableInitArg->new( size => 1 ) };
+like( $@, qr/unknown attribute.+: size/,
+      'ImmutableInitArg blows up when given attribute with undef init_arg' );
+
+eval { ImmutableInitArg->new( other => 1 ) };
+is( $@, '',
+    'ImmutableInitArg works when given proper init_arg' );
+
+eval { Immutable->new( thing => 1, bad => 99 ) };
+like( $@, qr/unknown attribute.+: bad/,
+      'strict constructor in immutable class blows up on unknown params' );
+
+eval { ImmutableTricky->new( thing => 1, spy => 99 ) };
+is( $@, '',
+    'immutable class can work around strict constructor by deleting params in BUILD()' );
+
+eval { ImmutableTricky->new( thing => 1, agent => 99 ) };
+like( $@, qr/unknown attribute.+: agent/,
+      'ImmutableTricky still blows up on unknown params other than spy' );

Added: branches/upstream/libmoosex-strictconstructor-perl/current/t/perlcritic.t
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/t/perlcritic.t?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/t/perlcritic.t (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/t/perlcritic.t Wed May 28 14:17:15 2008
@@ -1,0 +1,13 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+
+plan skip_all => 'This test is only run for the module author'
+    unless -d '.svn' || $ENV{IS_MAINTAINER};
+
+eval 'use Test::Perl::Critic ( -severity => 4 )';
+plan skip_all => 'Test::Perl::Critic required for testing POD' if $@;
+
+all_critic_ok();

Added: branches/upstream/libmoosex-strictconstructor-perl/current/t/pod-coverage.t
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/t/pod-coverage.t?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/t/pod-coverage.t (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/t/pod-coverage.t Wed May 28 14:17:15 2008
@@ -1,0 +1,14 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+
+plan skip_all => 'This test is only run for the module author'
+    unless -d '.svn' || $ENV{IS_MAINTAINER};
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"
+    if $@;
+
+all_pod_coverage_ok();

Added: branches/upstream/libmoosex-strictconstructor-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/branches/upstream/libmoosex-strictconstructor-perl/current/t/pod.t?rev=20469&op=file
==============================================================================
--- branches/upstream/libmoosex-strictconstructor-perl/current/t/pod.t (added)
+++ branches/upstream/libmoosex-strictconstructor-perl/current/t/pod.t Wed May 28 14:17:15 2008
@@ -1,0 +1,13 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+
+plan skip_all => 'This test is only run for the module author'
+    unless -d '.svn' || $ENV{IS_MAINTAINER};
+
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+
+all_pod_files_ok();




More information about the Pkg-perl-cvs-commits mailing list