diff -Nru libstruct-dumb-perl-0.08/Build.PL libstruct-dumb-perl-0.09/Build.PL --- libstruct-dumb-perl-0.08/Build.PL 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/Build.PL 2016-03-09 17:51:22.000000000 +0000 @@ -5,11 +5,13 @@ my $build = Module::Build->new( module_name => 'Struct::Dumb', - build_requires => { + test_requires => { 'Test::Fatal' => 0, 'Test::More' => '0.88', # done_testing }, - auto_configure_requires => 0, # Don't add M::B to configure_requires + configure_requires => { + 'Module::Build' => '0.4004', # test_requires + }, license => 'perl', create_makefile_pl => 'traditional', create_license => 1, diff -Nru libstruct-dumb-perl-0.08/Changes libstruct-dumb-perl-0.09/Changes --- libstruct-dumb-perl-0.08/Changes 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/Changes 2016-03-09 17:51:22.000000000 +0000 @@ -1,5 +1,9 @@ Revision history for Struct-Dumb +0.09 2016/03/09 17:49:17 + [CHANGES] + * Allow callers to allow ARRAY dereference for special circumstances + 0.08 2015/12/15 17:45:46 [CHANGES] * Support perl 5.8.x (which lacks overloading.pm) diff -Nru libstruct-dumb-perl-0.08/debian/changelog libstruct-dumb-perl-0.09/debian/changelog --- libstruct-dumb-perl-0.08/debian/changelog 2015-12-21 19:26:26.000000000 +0000 +++ libstruct-dumb-perl-0.09/debian/changelog 2016-03-12 17:57:43.000000000 +0000 @@ -1,3 +1,22 @@ +libstruct-dumb-perl (0.09-1) unstable; urgency=medium + + * Team upload. + + [ Salvatore Bonaccorso ] + * debian/control: Use HTTPS transport protocol for Vcs-Git URI + + [ Lucas Kanashiro ] + * Add debian/upstream/metadata + * Import upstream version 0.09 + * Update years of upstream copyright + * Update Debian packaging copyright + * Declare compliance with Debian policy 3.9.7 + + [ gregor herrmann ] + * Make build dependency on libmodule-build-perl versioned. + + -- Lucas Kanashiro Sat, 12 Mar 2016 14:51:39 -0300 + libstruct-dumb-perl (0.08-1) unstable; urgency=medium * New upstream release. diff -Nru libstruct-dumb-perl-0.08/debian/control libstruct-dumb-perl-0.09/debian/control --- libstruct-dumb-perl-0.08/debian/control 2015-12-21 19:26:26.000000000 +0000 +++ libstruct-dumb-perl-0.09/debian/control 2016-03-12 17:57:43.000000000 +0000 @@ -5,13 +5,13 @@ Testsuite: autopkgtest-pkg-perl Priority: optional Build-Depends: debhelper (>= 9), - libmodule-build-perl, + libmodule-build-perl (>= 0.400400), perl Build-Depends-Indep: libtest-fatal-perl, libtest-pod-perl -Standards-Version: 3.9.6 +Standards-Version: 3.9.7 Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/libstruct-dumb-perl.git -Vcs-Git: git://anonscm.debian.org/pkg-perl/packages/libstruct-dumb-perl.git +Vcs-Git: https://anonscm.debian.org/git/pkg-perl/packages/libstruct-dumb-perl.git Homepage: https://metacpan.org/release/Struct-Dumb Package: libstruct-dumb-perl diff -Nru libstruct-dumb-perl-0.08/debian/copyright libstruct-dumb-perl-0.09/debian/copyright --- libstruct-dumb-perl-0.08/debian/copyright 2015-12-21 19:26:26.000000000 +0000 +++ libstruct-dumb-perl-0.09/debian/copyright 2016-03-12 17:57:43.000000000 +0000 @@ -4,11 +4,12 @@ Upstream-Name: Struct-Dumb Files: * -Copyright: 2012-2015, Paul Evans +Copyright: 2012-2016, Paul Evans License: Artistic or GPL-1+ Files: debian/* Copyright: 2014-2015, gregor herrmann + 2016, Lucas Kanashiro License: Artistic or GPL-1+ License: Artistic diff -Nru libstruct-dumb-perl-0.08/debian/upstream/metadata libstruct-dumb-perl-0.09/debian/upstream/metadata --- libstruct-dumb-perl-0.08/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ libstruct-dumb-perl-0.09/debian/upstream/metadata 2016-03-12 17:57:43.000000000 +0000 @@ -0,0 +1,4 @@ +--- +Archive: CPAN +Contact: Paul Evans +Name: Struct-Dumb diff -Nru libstruct-dumb-perl-0.08/lib/Struct/Dumb.pm libstruct-dumb-perl-0.09/lib/Struct/Dumb.pm --- libstruct-dumb-perl-0.08/lib/Struct/Dumb.pm 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/lib/Struct/Dumb.pm 2016-03-09 17:51:22.000000000 +0000 @@ -1,14 +1,14 @@ # You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # -# (C) Paul Evans, 2012-2015 -- leonerd@leonerd.org.uk +# (C) Paul Evans, 2012-2016 -- leonerd@leonerd.org.uk package Struct::Dumb; use strict; use warnings; -our $VERSION = '0.08'; +our $VERSION = '0.09'; use Carp; @@ -220,10 +220,14 @@ *{"${caller}::$predicate"} = sub { ( ref($_[0]) || "" ) eq $pkg }; } + *{"${pkg}::_forbid_arrayification"} = sub { + return if !HAVE_OVERLOADING and caller eq __PACKAGE__; + croak "Cannot use $pkg as an ARRAY reference" + }; + require overload; $pkg->overload::OVERLOAD( - '@{}' => sub { return $_[0] if !HAVE_OVERLOADING and caller eq __PACKAGE__; - croak "Cannot use $pkg as an ARRAY reference" }, + '@{}' => sub { $_[0]->_forbid_arrayification; return $_[0] }, '0+' => sub { refaddr $_[0] }, '""' => sub { sprintf "%s=Struct::Dumb(%#x)", $pkg, refaddr $_[0] }, 'bool' => sub { 1 }, @@ -274,6 +278,30 @@ =cut +=head1 NOTES + +=head2 Allowing ARRAY dereference + +The way that forbidding access to instances as if they were ARRAY references +is currently implemented uses an internal method on the generated structure +class called C<_forbid_arrayification>. If special circumstances require that +this exception mechanism be bypassed, the method can be overloaded with an +empty C body, allowing the struct instances in that class to be +accessed like normal ARRAY references. For good practice this should be +limited by a C override. + +For example, L needs to access the instances as plain ARRAY +references so it can walk the data structure looking for reference cycles. + + use Devel::Cycle; + + { + no warnings 'redefine'; + local *Point::_forbid_arrayification = sub {}; + + memory_cycle_ok( $point ); + } + =head1 TODO =over 4 diff -Nru libstruct-dumb-perl-0.08/LICENSE libstruct-dumb-perl-0.09/LICENSE --- libstruct-dumb-perl-0.08/LICENSE 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/LICENSE 2016-03-09 17:51:22.000000000 +0000 @@ -1,4 +1,4 @@ -This software is copyright (c) 2015 by Paul Evans . +This software is copyright (c) 2016 by Paul Evans . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. @@ -12,7 +12,7 @@ --- The GNU General Public License, Version 1, February 1989 --- -This software is Copyright (c) 2015 by Paul Evans . +This software is Copyright (c) 2016 by Paul Evans . This is free software, licensed under: @@ -272,7 +272,7 @@ --- The Artistic License 1.0 --- -This software is Copyright (c) 2015 by Paul Evans . +This software is Copyright (c) 2016 by Paul Evans . This is free software, licensed under: diff -Nru libstruct-dumb-perl-0.08/Makefile.PL libstruct-dumb-perl-0.09/Makefile.PL --- libstruct-dumb-perl-0.08/Makefile.PL 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/Makefile.PL 2016-03-09 17:51:22.000000000 +0000 @@ -1,13 +1,10 @@ -# Note: this file was auto-generated by Module::Build::Compat version 0.4211 +# Note: this file was auto-generated by Module::Build::Compat version 0.4214 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Struct::Dumb', 'VERSION_FROM' => 'lib/Struct/Dumb.pm', - 'PREREQ_PM' => { - 'Test::Fatal' => 0, - 'Test::More' => '0.88' - }, + 'PREREQ_PM' => {}, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} diff -Nru libstruct-dumb-perl-0.08/META.json libstruct-dumb-perl-0.09/META.json --- libstruct-dumb-perl-0.08/META.json 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/META.json 2016-03-09 17:51:22.000000000 +0000 @@ -4,7 +4,7 @@ "Paul Evans " ], "dynamic_config" : 1, - "generated_by" : "Module::Build version 0.4211", + "generated_by" : "Module::Build version 0.4214", "license" : [ "perl_5" ], @@ -14,7 +14,12 @@ }, "name" : "Struct-Dumb", "prereqs" : { - "build" : { + "configure" : { + "requires" : { + "Module::Build" : "0.4004" + } + }, + "test" : { "requires" : { "Test::Fatal" : "0", "Test::More" : "0.88" @@ -24,7 +29,7 @@ "provides" : { "Struct::Dumb" : { "file" : "lib/Struct/Dumb.pm", - "version" : "0.08" + "version" : "0.09" } }, "release_status" : "stable", @@ -33,5 +38,6 @@ "http://dev.perl.org/licenses/" ] }, - "version" : "0.08" + "version" : "0.09", + "x_serialization_backend" : "JSON::PP version 2.27300" } diff -Nru libstruct-dumb-perl-0.08/META.yml libstruct-dumb-perl-0.09/META.yml --- libstruct-dumb-perl-0.08/META.yml 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/META.yml 2016-03-09 17:51:22.000000000 +0000 @@ -5,8 +5,10 @@ build_requires: Test::Fatal: '0' Test::More: '0.88' +configure_requires: + Module::Build: '0.4004' dynamic_config: 1 -generated_by: 'Module::Build version 0.4211, CPAN::Meta::Converter version 2.150001' +generated_by: 'Module::Build version 0.4214, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -15,7 +17,8 @@ provides: Struct::Dumb: file: lib/Struct/Dumb.pm - version: '0.08' + version: '0.09' resources: license: http://dev.perl.org/licenses/ -version: '0.08' +version: '0.09' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -Nru libstruct-dumb-perl-0.08/README libstruct-dumb-perl-0.09/README --- libstruct-dumb-perl-0.08/README 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/README 2016-03-09 17:51:22.000000000 +0000 @@ -1,71 +1,71 @@ NAME - `Struct::Dumb' - make simple lightweight record-like structures + + Struct::Dumb - make simple lightweight record-like structures SYNOPSIS + use Struct::Dumb; - + struct Point => [qw( x y )]; - + my $point = Point(10, 20); - + printf "Point is at (%d, %d)\n", $point->x, $point->y; - + $point->y = 30; printf "Point is now at (%d, %d)\n", $point->x, $point->y; - struct Point3D => [qw( x y z )], named_constructor => 1; - + my $point3d = Point3D( z => 12, x => 100, y => 50 ); - + printf "Point3d's height is %d\n", $point3d->z; - struct Point3D => [qw( x y z )], predicate => "is_Point3D"; - + my $point3d = Point3D( 1, 2, 3 ); - + printf "This is a Point3D\n" if is_Point3D( $point3d ); - use Struct::Dumb qw( -named_constructors ) - + struct Point3D => [qw( x y z ]; - + my $point3d = Point3D( x => 100, z => 12, y => 50 ); DESCRIPTION - `Struct::Dumb' creates record-like structure types, similar to the - `struct' keyword in C, C++ or C#, or `Record' in Pascal. An invocation - of this module will create a construction function which returns new - object references with the given field values. These references all - respond to lvalue methods that access or modify the values stored. - - It's specifically and intentionally not meant to be an object class. You - cannot subclass it. You cannot provide additional methods. You cannot - apply roles or mixins or metaclasses or traits or antlers or whatever - else is in fashion this week. + + Struct::Dumb creates record-like structure types, similar to the struct + keyword in C, C++ or C#, or Record in Pascal. An invocation of this + module will create a construction function which returns new object + references with the given field values. These references all respond to + lvalue methods that access or modify the values stored. + + It's specifically and intentionally not meant to be an object class. + You cannot subclass it. You cannot provide additional methods. You + cannot apply roles or mixins or metaclasses or traits or antlers or + whatever else is in fashion this week. On the other hand, it is tiny, creates cheap lightweight array-backed structures, uses nothing outside of core. It's intended simply to be a slightly nicer way to store data structures, where otherwise you might - be tempted to abuse a hash, complete with the risk of typoing key names. - The constructor will `croak' if passed the wrong number of arguments, as - will attempts to refer to fields that don't exist. Accessor-mutators - will `croak' if invoked with arguments. (This helps detect likely bugs - such as accidentally passing in the new value as an argument, or - attempting to invoke a stored `CODE' reference by passing argument - values directly to the accessor.) + be tempted to abuse a hash, complete with the risk of typoing key + names. The constructor will croak if passed the wrong number of + arguments, as will attempts to refer to fields that don't exist. + Accessor-mutators will croak if invoked with arguments. (This helps + detect likely bugs such as accidentally passing in the new value as an + argument, or attempting to invoke a stored CODE reference by passing + argument values directly to the accessor.) $ perl -E 'use Struct::Dumb; struct Point => [qw( x y )]; Point(30)' usage: main::Point($x, $y) at -e line 1 - + $ perl -E 'use Struct::Dumb; struct Point => [qw( x y )]; Point(10,20)->z' main::Point does not have a 'z' field at -e line 1 - + $ perl -E 'use Struct::Dumb; struct Point => [qw( x y )]; Point(1,2)->x(3)' main::Point->x invoked with arguments at -e line 1. @@ -74,21 +74,24 @@ be relied on by using code. Attempting to dereference the object as an ARRAY will throw an exception. - CONSTRUCTOR FORMS - The `struct' and `readonly_struct' declarations create two different - kinds of constructor function, depending on the setting of the - `named_constructor' option. When false, the constructor takes positional + CONSTRUCTOR FORMS + + The struct and readonly_struct declarations create two different kinds + of constructor function, depending on the setting of the + named_constructor option. When false, the constructor takes positional values in the same order as the fields were declared. When true, the constructor takes a key/value pair list in no particular order, giving the value of each named field. - This option can be specified to the `struct' and `readonly_struct' + This option can be specified to the struct and readonly_struct functions. It defaults to false, but it can be set on a per-package - basis to default true by supplying the `-named_constructors' option on - the `use' statement. + basis to default true by supplying the -named_constructors option on + the use statement. FUNCTIONS - struct + + struct + struct $name => [ @fieldnames ], named_constructor => (1|0), predicate => "is_$name"; @@ -101,29 +104,59 @@ Takes the following options: named_constructor => BOOL - Determines whether the structure will take positional or named - arguments. + + Determines whether the structure will take positional or named + arguments. predicate => STR - If defined, gives the name of a second function to export to the - caller's namespace. This function will be a type test predicate; - that is, a function that takes a single argmuent, and returns true - if-and-only-if that argument is an instance of this structure type. - readonly_struct + If defined, gives the name of a second function to export to the + caller's namespace. This function will be a type test predicate; that + is, a function that takes a single argmuent, and returns true + if-and-only-if that argument is an instance of this structure type. + + readonly_struct + readonly_struct $name => [ @fieldnames ], ... - Similar to struct, but instances of this type are immutable once + Similar to "struct", but instances of this type are immutable once constructed. The field accessor methods will not be marked with the - `:lvalue' attribute. + :lvalue attribute. + + Takes the same options as "struct". + +NOTES - Takes the same options as struct. + Allowing ARRAY dereference + + The way that forbidding access to instances as if they were ARRAY + references is currently implemented uses an internal method on the + generated structure class called _forbid_arrayification. If special + circumstances require that this exception mechanism be bypassed, the + method can be overloaded with an empty sub {} body, allowing the struct + instances in that class to be accessed like normal ARRAY references. + For good practice this should be limited by a local override. + + For example, Devel::Cycle needs to access the instances as plain ARRAY + references so it can walk the data structure looking for reference + cycles. + + use Devel::Cycle; + + { + no warnings 'redefine'; + local *Point::_forbid_arrayification = sub {}; + + memory_cycle_ok( $point ); + } TODO - * Consider adding an `coerce_hash' option, giving name of another - function to convert structs to key/value pairs, or a HASH ref. + + * Consider adding an coerce_hash option, giving name of another + function to convert structs to key/value pairs, or a HASH ref. AUTHOR + Paul Evans diff -Nru libstruct-dumb-perl-0.08/t/01point.t libstruct-dumb-perl-0.09/t/01point.t --- libstruct-dumb-perl-0.08/t/01point.t 2015-12-15 17:51:16.000000000 +0000 +++ libstruct-dumb-perl-0.09/t/01point.t 2016-03-09 17:51:22.000000000 +0000 @@ -38,6 +38,14 @@ qr/^Cannot use main::Point as an ARRAY reference at \S+ line \d+\.?\n/, 'Array deref throws exception' ); +ok( !( local $@ = exception { + no warnings 'redefine'; + local *Point::_forbid_arrayification = sub {}; + @{ Point(2, 2) }; + } ), + 'Array deref succeeds with locally-overridden forbid function' ) or + diag( "Exception was $@" ); + like( exception { $point->x(50) }, qr/^main::Point->x invoked with arguments at \S+ line \d+\.?\n/, 'Accessor with arguments throws exception' );