CONTRIBUTING 000664 001750 001750 6146 12404143773 14326 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 NAME
CONTRIBUTING
DESCRIPTION
If you're reading this document, that means you might be thinking about
helping me out with this project. Thanks!
Here's some ways you could help out:
* Bug reports
Found a bug? Great! (Well, not so great I suppose.)
The place to report them is . Don't e-mail me
about it, as your e-mail is more than likely to get lost amongst the
spam.
An example script clearly demonstrating the bug (preferably written
using Test::More) would be greatly appreciated.
* Patches
If you've found a bug and written a fix for it, even better!
Generally speaking you should check out the latest copy of the code
from the source repository rather than using the CPAN distribution.
The file META.yml should contain a link to the source repository. If
not, then try or submit a bug report.
(As far as I'm concerned the lack of a link is a bug.) Many of my
distributions are also mirrored at .
To submit the patch, do a pull request on GitHub or Bitbucket, or
attach a diff file to a bug report. Unless otherwise stated, I'll
assume that your contributions are licensed under the same terms as
the rest of the project.
(If using git, feel free to work in a branch. For Mercurial, I'd
prefer bookmarks within the default branch.)
* Documentation
If there's anything unclear in the documentation, please submit this
as a bug report or patch as above.
Non-toy example scripts that I can bundle would also be appreciated.
* Translation
Translations of documentation would be welcome.
For translations of error messages and other strings embedded in the
code, check with me first. Sometimes the English strings may not in
a stable state, so it would be a waste of time translating them.
Coding Style
I tend to write using something approximating the Allman style, using
tabs for indentation and Unix-style line breaks.
*
*
I nominally encode all source files as UTF-8, though in practice most of
them use a 7-bit-safe ASCII-compatible subset of UTF-8.
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENCE
Copyright (c) 2012-2014 by Toby Inkster.
CONTRIBUTING is available under three different licences permitting its
redistribution: the CC-BY-SA_UK-2.0 licence, plus the same licences as
Perl itself, which is distributed under the GNU General Public Licence
version 1, and the Artistic Licence.
This file is licensed under the Creative Commons Attribution-ShareAlike
2.0 UK: England & Wales License. To view a copy of this license, visit
.
This file is free software; you can redistribute it and/or modify it
under the same terms as the Perl 5 programming language system itself.
COPYRIGHT 000664 001750 001750 3001 12404143773 13752 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: MooX-Struct
Upstream-Contact: Toby Inkster (TOBYINK)
Source: https://metacpan.org/release/MooX-Struct
Files: t/01basic.t
t/02basicusage.t
t/03inherit.t
t/04flag.t
t/05methods.t
t/06sigils.t
t/07overloading.t
t/08alt-constructor.t
t/09roles.t
t/10strict-constructor.t
t/11extend.t
t/12lexical.t
t/13basestruct.t
t/14trace.t
t/96processor.t
t/97dataprinter.t
t/98baseclass.t
t/99lazy.t
Copyright: This software is copyright (c) 2012 by Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: CONTRIBUTING
INSTALL
LICENSE
NEWS
examples/triangle.pl
t/readme.pod
Copyright: Unknown
License: Unknown
Files: Changes
META.json
META.yml
dist.ini
doap.ttl
Copyright: Copyright 2014 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: README
lib/MooX/Struct.pm
lib/MooX/Struct/Util.pm
Copyright: This software is copyright (c) 2012-2013 by Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: COPYRIGHT
CREDITS
SIGNATURE
Copyright: None
License: public-domain
Files: Makefile.PL
Copyright: Copyright 2013 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
License: Artistic-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The Artistic License 1.0
License: GPL-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
CREDITS 000664 001750 001750 243 12404143767 13467 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 Maintainer:
- Toby Inkster (TOBYINK)
Contributor:
- NOBODY
Thanks:
-
- Chris Prather (PERIGRIN)
Changes 000664 001750 001750 5352 12404143767 13770 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 MooX-Struct
===========
Created: 2012-10-04
Home page:
Bug tracker:
Maintainer: Toby Inkster (TOBYINK)
0.013 2014-09-10
[ Packaging ]
- Switch to Dist::Inkt.
0.012 2013-05-18
[ Bug Fixes ]
- Stop relying on hash order to pass t/14trace.t.
0.011 2013-05-12
[ Documentation ]
- Add CAVEATS section to documentation.
Chris Prather++
0.010 2012-12-21 100% Devel::Cover coverage!
[ Bug Fixes ]
- Passing objects overloading hash dereference to the constructor was
supposed to be supported; now it actually works.
- Processing flags in EXTEND method could cause infinite loop.
- Usage with Data::Printer was causing an exception related to prototypes.
[ Other ]
- Added: Many new test cases.
0.009 2012-12-18
[ Bug Fixes ]
- Fix an internal issue in MooX::Struct::Processor, whereby it would
ignore attributes inherited from the default base class when building
the FIELDS method.
[ Packaging ]
- Moar test cases.
[ Other ]
- Attributes inherited from roles are no longer included in FIELDS.
- Moo-style constructor is no longer strict. (This may change back!)
0.008 2012-12-17
[ Documentation ]
- Add pod to test suite.
[ Other ]
- Added: Provide '-class' feature (currently tested for but not
documented).
0.007 2012-10-28
- Added: Allow namespace::clean behaviour to be avoided via a '-retain'
flag.
0.006 2012-10-09
[ Bug Fixes ]
- Fix minor pod syntax error.
[ Other ]
- Added: Allow structs to consume roles using '-with' option.
- Added: Bundle MooX::Struct::Util.
- Added: New experimental method 'EXTEND'.
- Constructor is now strict; it will croak if passed hash keys it doesn't
recognise.
- Removed: Dropped 'object_id' alias for 'OBJECT_ID'.
0.005 2012-10-08
- Added: New method 'CLONE'.
- Added: New method 'FIELDS'.
- Added: New method 'TO_HASH'.
- Added: New method 'TO_STRING'.
- Added: New method 'TYPE'.
- Added: Overload a lot of operations on structs.
- Added: Provide Point[$x,$y] style constructor.
- Added: Special Data::Printer support.
- The 'object_id' method is now called 'OBJECT_ID'.
0.004 2012-10-07
[ Bug Fixes ]
- Workaround strange closure bug in Perl < 5.14.
Fixes RT#80043.
0.003 2012-10-05
[ Bug Fixes ]
- Broken and undocumented sigils feature is now working, documented and
tested.
[ Other ]
- Added: New bang postfix sigil, indicating a required attribute.
- The '-isa' feature for setting superclasses is now called '-extends'.
0.002 2012-10-05
[ Packaging ]
- List dependencies.
0.001 2012-10-04 Initial release
INSTALL 000664 001750 001750 1665 12404143766 13530 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 Installing MooX-Struct should be straightforward.
INSTALLATION WITH CPANMINUS
If you have cpanm, you only need one line:
% cpanm MooX::Struct
If you are installing into a system-wide directory, you may need to pass
the "-S" flag to cpanm, which uses sudo to install the module:
% cpanm -S MooX::Struct
INSTALLATION WITH THE CPAN SHELL
Alternatively, if your CPAN shell is set up, you should just be able to
do:
% cpan MooX::Struct
MANUAL INSTALLATION
As a last resort, you can manually install it. Download the tarball and
unpack it.
Consult the file META.json for a list of pre-requisites. Install these
first.
To build MooX-Struct:
% perl Makefile.PL
% make && make test
Then install it:
% make install
If you are installing into a system-wide directory, you may need to run:
% sudo make install
LICENSE 000664 001750 001750 43655 12404143766 13531 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 This software is copyright (c) 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
MANIFEST 000664 001750 001750 747 12404143773 13606 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 CONTRIBUTING
COPYRIGHT
CREDITS
Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
NEWS
README
SIGNATURE
dist.ini
doap.ttl
examples/triangle.pl
lib/MooX/Struct.pm
lib/MooX/Struct/Util.pm
t/01basic.t
t/02basicusage.t
t/03inherit.t
t/04flag.t
t/05methods.t
t/06sigils.t
t/07overloading.t
t/08alt-constructor.t
t/09roles.t
t/10strict-constructor.t
t/11extend.t
t/12lexical.t
t/13basestruct.t
t/14trace.t
t/96processor.t
t/97dataprinter.t
t/98baseclass.t
t/99lazy.t
t/readme.pod
META.json 000664 001750 001750 4206 12404143773 14110 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 {
"abstract" : "make simple lightweight record-like structures that make sounds like cows",
"author" : [
"Toby Inkster (TOBYINK) "
],
"dynamic_config" : 0,
"generated_by" : "Moose::Meta::Class::__ANON__::SERIAL::11 version , CPAN::Meta::Converter version 2.140640",
"keywords" : [],
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "MooX-Struct",
"no_index" : {
"directory" : [
"eg",
"examples",
"inc",
"t",
"xt"
]
},
"optional_features" : {},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.17"
}
},
"runtime" : {
"requires" : {
"B::Hooks::EndOfScope" : "0",
"Data::OptList" : "0",
"Moo" : "1.000000",
"Object::ID" : "0",
"Scalar::Does" : "0",
"Sub::Install" : "0",
"namespace::clean" : "0"
}
},
"test" : {
"requires" : {
"Test::More" : "0.61"
}
}
},
"provides" : {
"MooX::Struct" : {
"file" : "lib/MooX/Struct.pm",
"version" : "0.013"
},
"MooX::Struct::Processor" : {
"file" : "lib/MooX/Struct.pm",
"version" : "0.013"
},
"MooX::Struct::Util" : {
"file" : "lib/MooX/Struct/Util.pm",
"version" : "0.013"
}
},
"release_status" : "stable",
"resources" : {
"X_identifier" : "http://purl.org/NET/cpan-uri/dist/MooX-Struct/project",
"bugtracker" : {
"web" : "http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct"
},
"homepage" : "https://metacpan.org/release/MooX-Struct",
"license" : [
"http://dev.perl.org/licenses/"
],
"repository" : {
"type" : "git",
"url" : "git://github.com/tobyink/p5-moox-struct.git",
"web" : "https://github.com/tobyink/p5-moox-struct"
}
},
"version" : "0.013",
"x_contributors" : [
"NOBODY"
]
}
META.yml 000664 001750 001750 2454 12404143773 13743 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 ---
abstract: 'make simple lightweight record-like structures that make sounds like cows'
author:
- 'Toby Inkster (TOBYINK) '
build_requires:
Test::More: '0.61'
configure_requires:
ExtUtils::MakeMaker: '6.17'
dynamic_config: 0
generated_by: 'Moose::Meta::Class::__ANON__::SERIAL::11 version , CPAN::Meta::Converter version 2.140640'
keywords: []
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: MooX-Struct
no_index:
directory:
- eg
- examples
- inc
- t
- xt
optional_features: {}
provides:
MooX::Struct:
file: lib/MooX/Struct.pm
version: '0.013'
MooX::Struct::Processor:
file: lib/MooX/Struct.pm
version: '0.013'
MooX::Struct::Util:
file: lib/MooX/Struct/Util.pm
version: '0.013'
requires:
B::Hooks::EndOfScope: '0'
Data::OptList: '0'
Moo: '1.000000'
Object::ID: '0'
Scalar::Does: '0'
Sub::Install: '0'
namespace::clean: '0'
resources:
X_identifier: http://purl.org/NET/cpan-uri/dist/MooX-Struct/project
bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct
homepage: https://metacpan.org/release/MooX-Struct
license: http://dev.perl.org/licenses/
repository: git://github.com/tobyink/p5-moox-struct.git
version: '0.013'
x_contributors:
- NOBODY
Makefile.PL 000664 001750 001750 12470 12404143773 14463 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 use strict;
use ExtUtils::MakeMaker 6.17;
my $EUMM = eval( $ExtUtils::MakeMaker::VERSION );
my $meta = {
"abstract" => "make simple lightweight record-like structures that make sounds like cows",
"author" => ["Toby Inkster (TOBYINK) "],
"dynamic_config" => 0,
"generated_by" => "Moose::Meta::Class::__ANON__::SERIAL::11 version , CPAN::Meta::Converter version 2.140640",
"keywords" => [],
"license" => ["perl_5"],
"meta-spec" => {
url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
version => 2,
},
"name" => "MooX-Struct",
"no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] },
"prereqs" => {
configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } },
runtime => {
requires => {
"B::Hooks::EndOfScope" => 0,
"Data::OptList" => 0,
"Moo" => "1.000000",
"namespace::clean" => 0,
"Object::ID" => 0,
"Scalar::Does" => 0,
"Sub::Install" => 0,
},
},
test => { requires => { "Test::More" => 0.61 } },
},
"provides" => {
"MooX::Struct" => { file => "lib/MooX/Struct.pm", version => 0.013 },
"MooX::Struct::Processor" => { file => "lib/MooX/Struct.pm", version => 0.013 },
"MooX::Struct::Util" => { file => "lib/MooX/Struct/Util.pm", version => 0.013 },
},
"release_status" => "stable",
"resources" => {
bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct" },
homepage => "https://metacpan.org/release/MooX-Struct",
license => ["http://dev.perl.org/licenses/"],
repository => {
type => "git",
url => "git://github.com/tobyink/p5-moox-struct.git",
web => "https://github.com/tobyink/p5-moox-struct",
},
X_identifier => "http://purl.org/NET/cpan-uri/dist/MooX-Struct/project",
},
"version" => 0.013,
"x_contributors" => ["NOBODY"],
};
my %dynamic_config;
my %WriteMakefileArgs = (
ABSTRACT => $meta->{abstract},
AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]),
DISTNAME => $meta->{name},
VERSION => $meta->{version},
EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ],
NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n },
test => { TESTS => "t/*.t" },
%dynamic_config,
);
$WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001;
sub deps
{
my %r;
for my $stage (@_)
{
for my $dep (keys %{$meta->{prereqs}{$stage}{requires}})
{
next if $dep eq 'perl';
my $ver = $meta->{prereqs}{$stage}{requires}{$dep};
$r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep};
}
}
\%r;
}
my ($build_requires, $configure_requires, $runtime_requires, $test_requires);
if ($EUMM >= 6.6303)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{TEST_REQUIRES} ||= deps('test');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.5503)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.52)
{
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test');
}
else
{
$WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime');
}
{
my ($minperl) = reverse sort(
grep defined && /^[0-9]+(\.[0-9]+)?$/,
map $meta->{prereqs}{$_}{requires}{perl},
qw( configure build runtime )
);
if (defined($minperl))
{
die "Installing $meta->{name} requires Perl >= $minperl"
unless $] >= $minperl;
$WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl
if $EUMM >= 6.48;
}
}
sub FixMakefile
{
return unless -d 'inc';
my $file = shift;
local *MAKEFILE;
open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
my $makefile = do { local $/; };
close MAKEFILE or die $!;
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
print MAKEFILE $makefile or die $!;
close MAKEFILE or die $!;
}
my $mm = WriteMakefile(%WriteMakefileArgs);
FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile');
exit(0);
NEWS 000664 001750 001750 343 12404143765 13145 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 0.010 - 2012-12-21
100% coverage on Devel::Cover.
0.009 - 2012-12-18
Some incompatible changes...
- traditional Moose/Moo-style constructor is no longer strict
- attributes inherited from roles no longer appear in FIELDS
README 000664 001750 001750 23500 12404143766 13367 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 NAME
MooX::Struct - make simple lightweight record-like structures that make
sounds like cows
SYNOPSIS
use MooX::Struct
Point => [ 'x', 'y' ],
Point3D => [ -extends => ['Point'], 'z' ],
;
my $origin = Point3D->new( x => 0, y => 0, z => 0 );
# or...
my $origin = Point3D[ 0, 0, 0 ];
DESCRIPTION
MooX::Struct allows you to create cheap struct-like classes for your data
using Moo.
While similar in spirit to MooseX::Struct and Class::Struct, MooX::Struct
has a somewhat different usage pattern. Rather than providing you with a
`struct` keyword which can be used to define structs, you define all the
structs as part of the `use` statement. This means they happen at compile
time.
A struct is just an "anonymous" Moo class. MooX::Struct creates this class
for you, and installs a lexical alias for it in your namespace. Thus your
module can create a "Point3D" struct, and some other module can too, and
they won't interfere with each other. All struct classes inherit from
MooX::Struct.
Arguments for MooX::Struct are key-value pairs, where keys are the struct
names, and values are arrayrefs.
use MooX::Struct
Person => [qw/ name address /],
Company => [qw/ name address registration_number /];
The elements in the array are the attributes for the struct (which will be
created as read-only attributes), however certain array elements are
treated specially.
* As per the example in the "SYNOPSIS", `-extends` introduces a list of
parent classes for the struct. If not specified, then classes inherit
from MooX::Struct itself.
Structs can inherit from other structs, or from normal classes. If
inheriting from another struct, then you *must* define both in the
same `use` statement. Inheriting from a non-struct class is
discouraged.
# Not like this.
use MooX::Struct Point => [ 'x', 'y' ];
use MooX::Struct Point3D => [ -extends => ['Point'], 'z' ];
# Like this.
use MooX::Struct
Point => [ 'x', 'y' ],
Point3D => [ -extends => ['Point'], 'z' ],
;
* Similarly `-with` consumes a list of roles.
* If an attribute name is followed by a coderef, this is installed as a
method instead.
use MooX::Struct
Person => [
qw( name age sex ),
greet => sub {
my $self = shift;
CORE::say "Hello ", $self->name;
},
];
But if you're defining methods for your structs, then you've possibly
missed the point of them.
* If an attribute name is followed by an arrayref, these are used to set
the options for the attribute. For example:
use MooX::Struct
Person => [ name => [ is => 'ro', required => 1 ] ];
Using the `init_arg` option would probably break stuff. Don't do that.
* Attribute names may be "decorated" with prefix and postfix "sigils".
The prefix sigils of `@` and `%` specify that the attribute isa
arrayref or hashref respectively. (Blessed arrayrefs and hashrefs are
accepted; as are objects which overload `@{}` and `%{}`.) The prefix
sigil `$` specifies that the attribute value must not be an unblessed
arrayref or hashref. The prefix sigil `+` indicates the attribute is a
number, and provides a default value of 0, unless the attribute is
required. The postfix sigil `!` specifies that the attribute is
required.
use MooX::Struct
Person => [qw( $name! @children )];
Person->new(); # dies, name is required
Person->new( # dies, children should be arrayref
name => 'Bob',
children => 2,
);
Prior to the key-value list, some additional flags can be given. These
begin with hyphens. The flag `-rw` indicates that attributes should be
read-write rather than read-only.
use MooX::Struct -rw,
Person => [
qw( name age sex ),
greet => sub {
my $self = shift;
CORE::say "Hello ", $self->name;
},
];
The `-retain` flag can be used to indicate that MooX::Struct should not
use namespace::clean to enforce lexicalness on your struct class aliases.
Flags `-trace` and `-deparse` may be of use debugging.
Instantiating Structs
There are two supported methods of instatiating structs. You can use a
traditional class-like constructor with named parameters:
my $point = Point->new( x => 1, y => 2 );
Or you can use the abbreviated syntax with positional parameters:
my $point = Point[ 1, 2 ];
If you know about Moo and peek around in the source code for this module,
then I'm sure you can figure out additional ways to instantiate them, but
the above are the only supported two.
When inheritance or roles have been used, it might not always be clear
what order the positional parameters come in (though see the documentation
for the `FIELDS` below), so the traditional class-like style may be
preferred.
Methods
Structs are objects and thus have methods. You can define your own methods
as described above. MooX::Struct's built-in methods will always obey the
convention of being in ALL CAPS (except in the case of `_data_printer`).
By using lower-case letters to name your own methods, you can avoid naming
collisions.
The following methods are currently defined. Additionally all the standard
Perl (`isa`, `can`, etc) and Moo (`new`, `does`, etc) methods are
available.
`OBJECT_ID`
Returns a unique identifier for the object.
`FIELDS`
Returns a list of fields associated with the object. For the `Point3D`
struct in the SYNPOSIS, this would be 'x', 'y', 'z'.
The order the fields are returned in is equal to the order they must
be supplied for the positional constructor.
Attributes inherited from roles, or from non-struct base classes are
not included in `FIELDS`, and thus cannot be used in the positional
constructor.
`TYPE`
Returns the type name of the struct, e.g. 'Point3D'.
`TO_HASH`
Returns a reference to an unblessed hash where the object's fields are
the keys and the object's values are the hash values.
`TO_ARRAY`
Returns a reference to an unblessed array where the object's values
are the array items, in the same order as listed by `FIELDS`.
`TO_STRING`
Joins `TO_ARRAY` with whitespace. This is not necessarily a brilliant
stringification, but easy enough to overload:
use MooX::Struct
Point => [
qw( x y ),
TO_STRING => sub {
sprintf "(%d, %d)"), $_[0]->x, $_[0]->y;
},
]
;
`CLONE`
Creates a shallow clone of the object.
`EXTEND`
An exverimental feature.
Extend a class or object with additional attributes, methods, etc.
This method takes almost all the same arguments as `use MooX::Struct`,
albeit with some slight differences.
use MooX::Struct Point => [qw/ +x +y /];
my $point = Point[2, 3];
$point->EXTEND(-rw, q/+z/); # extend an object
$point->can('z'); # true
my $new_class = Point->EXTEND('+z'); # extend a class
my $point_3d = $new_class->new( x => 1, y => 2, z => 3 );
$point_3d->TYPE; # Point !
my $point_4d = $new_class->EXTEND(\"Point4D", '+t');
$point_4d->TYPE; # Point4D
my $origin = Point[]->EXTEND(-with => [qw/ Math::Role::Origin /]);
This feature has been included mostly because it's easy to implement
on top of the existing code for processing `use MooX::Struct`. Some
subsets of this functionality are sane, such as the ability to add
traits to an object. Others (like the ability to add a new
uninitialized, read-only attribute to an existing object) are less
sensible.
`BUILDARGS`
Moo internal fu.
`_data_printer`
Automatic pretty printing with Data::Printer.
use Data::Printer;
use MooX::Struct Point => [qw/ +x +y /];
my $origin = Point[];
p $origin;
With the exception of `FIELDS` and `TYPE`, any of these can be overridden
using the standard way of specifying methods for structs.
Overloading
MooX::Struct overloads stringification and array dereferencing. Objects
always evaluate to true in a boolean context. (Even if they stringify to
the empty string.)
CAVEATS
Because you only get an alias for the struct class, you need to be careful
with some idioms:
my $point = Point3D->new(x => 1, y => 2, z => 3);
$point->isa("Point3D"); # false!
$point->isa( Point3D ); # true
my %args = (...);
my $class = exists $args{z} ? "Point3D" : "Point"; # wrong!
$class->new(%args);
my $class = exists $args{z} ? Point3D : Point ; # right
$class->new(%args);
BUGS
Please report any bugs to
.
SEE ALSO
Moo, MooX::Struct::Util, MooseX::Struct, Class::Struct.
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENCE
This software is copyright (c) 2012-2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the
same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
SIGNATURE 000664 001750 001750 5440 12404143774 13755 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.73.
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 33317486c4fa2cf7fec85bf92ed38ac0f64233a0 CONTRIBUTING
SHA1 933eee61fb22125fb7639f840bf10f1683589152 COPYRIGHT
SHA1 1c8b157e82d74520f2dc07d6b5bef39cb24fdb60 CREDITS
SHA1 7c77a2c01a48f0c5243be84e5513704d9c157a1a Changes
SHA1 a6d167b6b05e6ccf711497d63a867605bfe892b7 INSTALL
SHA1 34f5e12514b91055de4b164a1f2327ef5c30ba53 LICENSE
SHA1 83169bd1483710e0049f185e9c09249bcf2bbb9b MANIFEST
SHA1 71b46e8c32c43cfa10c692c663959937ebf42eb9 META.json
SHA1 9ce5512fff554b3605a75e89cef71e1fac196fcc META.yml
SHA1 8168f4c51f61f3309285310e17c9efccaa075935 Makefile.PL
SHA1 7dfae4509a85273971fdcd835af7c9cc15dc6cd8 NEWS
SHA1 557534291fe8750be7ae0378fa02f9a3767dfa1e README
SHA1 31620717d6a86130ce847f10f865bcafb99aef79 dist.ini
SHA1 16c5e509dd2593a883294341cef7a44b2fbd4733 doap.ttl
SHA1 632ae6adc26897342739b02418ed3ef997ac072e examples/triangle.pl
SHA1 f75792a72add946569e5d3216e286fab7dd492ca lib/MooX/Struct.pm
SHA1 3792e1f5073f0a8e12f0861c17f295d45c5ff279 lib/MooX/Struct/Util.pm
SHA1 d26efcaebce8e74b5b9ce441b6d5ff229b1d7cde t/01basic.t
SHA1 2d605dd7f1b1abb5a935416f814026fb29f11817 t/02basicusage.t
SHA1 580e1e120c0c032a4788e44070e0c304fefc0b7c t/03inherit.t
SHA1 cbe7476e8bdb983f6860d02b79312246bc57c9df t/04flag.t
SHA1 c44ce05cbe2290ff8f8ee707bac73c1b6abb717a t/05methods.t
SHA1 1f850f2f737702baeb64cb160008cd689825c65e t/06sigils.t
SHA1 c86a5c14e7f73246721cf406319fda4d25b19970 t/07overloading.t
SHA1 c840db65cfe3371c012ba14672d5e93b7ae9e85a t/08alt-constructor.t
SHA1 e3b421daa199428b70bee7a1f0f4ebe305f0b102 t/09roles.t
SHA1 042fc931861d6003b10623eea4937abc8006648a t/10strict-constructor.t
SHA1 a3ac7ec30d564fd68e66940424ab791803f1e2c4 t/11extend.t
SHA1 923b254963531385ba70fbba732ec58b042504b3 t/12lexical.t
SHA1 226b6e5dd2bd5762283e2833ee4523d10012c506 t/13basestruct.t
SHA1 69c8d781dd2b397dd7019e20254ee45376116f1e t/14trace.t
SHA1 2ea288303c380732ec8cb667b2234a91d0030d33 t/96processor.t
SHA1 03844d7335e21197dc703389b95277654ea1c11a t/97dataprinter.t
SHA1 34532bdfdf4739460b6890098c3a0cc155393d86 t/98baseclass.t
SHA1 9ab4c3ee1177da1337a6913200302816f562005b t/99lazy.t
SHA1 d610ccf6c138bd58c79ebf6a58cab019ae98aa8c t/readme.pod
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEARECAAYFAlQQx/wACgkQzr+BKGoqfTkGAgCglh9l9CIk6F6aKG3abNESe2J/
MoQAn3L5BOdAmCfmWjtyx3QoOtNmIHeA
=xKZR
-----END PGP SIGNATURE-----
dist.ini 000664 001750 001750 74 12404143765 14073 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 ;;class='Dist::Inkt::Profile::TOBYINK'
;;name='MooX-Struct'
doap.ttl 000664 001750 001750 32437 12404143773 14166 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013 @prefix dc: .
@prefix doap: .
@prefix doap-bugs: .
@prefix doap-changeset: .
@prefix doap-deps: .
@prefix foaf: .
@prefix rdfs: .
@prefix xsd: .
dc:title "the same terms as the perl 5 programming language system itself".
a doap:Project;
dc:contributor ;
doap-bugs:issue ;
doap-deps:runtime-requirement [
doap-deps:on "B::Hooks::EndOfScope"^^doap-deps:CpanId;
], [ doap-deps:on "Data::OptList"^^doap-deps:CpanId ], [ doap-deps:on "Moo 1.000000"^^doap-deps:CpanId ], [ doap-deps:on "namespace::clean"^^doap-deps:CpanId ], [ doap-deps:on "Object::ID"^^doap-deps:CpanId ], [ doap-deps:on "Scalar::Does"^^doap-deps:CpanId ], [ doap-deps:on "Sub::Install"^^doap-deps:CpanId ];
doap-deps:test-requirement [ doap-deps:on "Test::More 0.61"^^doap-deps:CpanId ];
doap:bug-database ;
doap:created "2012-10-04"^^xsd:date;
doap:developer ;
doap:download-page ;
doap:homepage ;
doap:license ;
doap:maintainer ;
doap:name "MooX-Struct";
doap:programming-language "Perl";
doap:release , , , , , , , , , , , , ;
doap:repository [
a doap:GitRepository;
doap:browse ;
];
doap:shortdesc "make simple lightweight record-like structures that make sounds like cows".
a doap:Version;
rdfs:label "Initial release";
dc:identifier "MooX-Struct-0.001"^^xsd:string;
dc:issued "2012-10-04"^^xsd:date;
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.001"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.002"^^xsd:string;
dc:issued "2012-10-05"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Packaging;
rdfs:label "List dependencies.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.002"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.003"^^xsd:string;
dc:issued "2012-10-05"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "The '-isa' feature for setting superclasses is now called '-extends'.";
], [
a doap-changeset:Bugfix;
rdfs:label "Broken and undocumented sigils feature is now working, documented and tested.";
], [
a doap-changeset:Addition;
rdfs:label "New bang postfix sigil, indicating a required attribute.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.003"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.004"^^xsd:string;
dc:issued "2012-10-07"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Workaround strange closure bug in Perl < 5.14."@en;
doap-changeset:fixes ;
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.004"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.005"^^xsd:string;
dc:issued "2012-10-08"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "The 'object_id' method is now called 'OBJECT_ID'.";
], [
a doap-changeset:Addition;
rdfs:label "New method 'TO_STRING'.";
], [
a doap-changeset:Addition;
rdfs:label "New method 'TO_HASH'.";
], [
a doap-changeset:Addition;
rdfs:label "New method 'FIELDS'.";
], [
a doap-changeset:Addition;
rdfs:label "New method 'TYPE'.";
], [
a doap-changeset:Addition;
rdfs:label "New method 'CLONE'.";
], [
a doap-changeset:Addition;
rdfs:label "Provide Point[$x,$y] style constructor.";
], [
a doap-changeset:Addition;
rdfs:label "Overload a lot of operations on structs.";
], [
a doap-changeset:Addition;
rdfs:label "Special Data::Printer support.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.005"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.006"^^xsd:string;
dc:issued "2012-10-09"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Fix minor pod syntax error.";
], [
a doap-changeset:Addition;
rdfs:label "Bundle MooX::Struct::Util.";
], [
a doap-changeset:Addition;
rdfs:label "Allow structs to consume roles using '-with' option.";
], [
a doap-changeset:Change;
rdfs:label "Constructor is now strict; it will croak if passed hash keys it doesn't recognise.";
], [
a doap-changeset:Addition;
rdfs:label "New experimental method 'EXTEND'.";
], [
a doap-changeset:Removal;
rdfs:label "Dropped 'object_id' alias for 'OBJECT_ID'.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.006"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.007"^^xsd:string;
dc:issued "2012-10-28"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Addition;
rdfs:label "Allow namespace::clean behaviour to be avoided via a '-retain' flag.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.007"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.008"^^xsd:string;
dc:issued "2012-12-17"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Addition;
rdfs:label "Provide '-class' feature (currently tested for but not documented).";
], [
a doap-changeset:Documentation;
rdfs:label "Add pod to test suite.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.008"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.009"^^xsd:string;
dc:issued "2012-12-18"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Fix an internal issue in MooX::Struct::Processor, whereby it would ignore attributes inherited from the default base class when building the FIELDS method.";
], [
a doap-changeset:Packaging;
rdfs:label "Moar test cases.";
], [
a doap-changeset:Change;
rdfs:label "Moo-style constructor is no longer strict. (This may change back!)";
], [
a doap-changeset:Change;
rdfs:label "Attributes inherited from roles are no longer included in FIELDS.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.009"^^xsd:string.
a doap:Version;
rdfs:label "100% Devel::Cover coverage!";
dc:identifier "MooX-Struct-0.010"^^xsd:string;
dc:issued "2012-12-21"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Processing flags in EXTEND method could cause infinite loop.";
], [
a doap-changeset:Bugfix;
rdfs:label "Passing objects overloading hash dereference to the constructor was supposed to be supported; now it actually works.";
], [
a doap-changeset:Bugfix;
rdfs:label "Usage with Data::Printer was causing an exception related to prototypes.";
], [
a doap-changeset:Addition;
rdfs:label "Many new test cases.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.010"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.011"^^xsd:string;
dc:issued "2013-05-12"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Documentation;
rdfs:label "Add CAVEATS section to documentation.";
doap-changeset:thanks ;
rdfs:seeAlso ;
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.011"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.012"^^xsd:string;
dc:issued "2013-05-18"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Stop relying on hash order to pass t/14trace.t.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.012"^^xsd:string.
a doap:Version;
dc:identifier "MooX-Struct-0.013"^^xsd:string;
dc:issued "2014-09-10"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Packaging;
rdfs:label "Switch to Dist::Inkt.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.013"^^xsd:string.
a foaf:Person;
foaf:name "Chris Prather";
foaf:nick "PERIGRIN";
foaf:page .
a foaf:Person;
foaf:mbox ;
foaf:name "Toby Inkster";
foaf:nick "TOBYINK";
foaf:page .
a doap-bugs:Issue;
rdfs:label "Hmmm... not working in Perl < 5.14.";
dc:created "2012-10-06T21:54:22"^^xsd:dateTime;
dc:modified "2012-10-06T21:54:23"^^xsd:dateTime;
doap-bugs:assignee [ a foaf:Agent; foaf:nick "Nobody" ];
doap-bugs:id "80043"^^xsd:string;
doap-bugs:page ;
doap-bugs:reporter [
a foaf:Agent;
foaf:mbox ;
];
doap-bugs:status .
triangle.pl 000664 001750 001750 576 12404143765 16436 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/examples use strict;
use Data::Printer;
use MooX::Struct
Triangle => [qw/ $a! $b! $c! /],
Quad => [qw/ $a! $b! $c! $d! /],
Point => [qw/ +x +y /],
;
my $triangle = Triangle[
Point[0, 0],
Point[1, 1],
Point[1, 0],
];
my $square = Quad[
Point[0, 0],
Point[0, 1],
Point[1, 1],
Point[1, 0],
];
my %shapes = ( three_sided => [$triangle] , four_sided => [$square] );
p %shapes; 01basic.t 000664 001750 001750 1047 12404143766 14343 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Checks MooX::Struct compiles.
Prints out some key software versions.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More tests => 1;
BEGIN { use_ok('MooX::Struct') };
diag '';
diag sprintf("%-12s %s", q(Perl), $]);
diag sprintf("%-12s %s", $_, $_->VERSION)
for qw( MooX::Struct Moo );
02basicusage.t 000664 001750 001750 2611 12404143766 15367 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Basic MooX::Struct usage.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use Test::More tests => 12;
use MooX::Struct
Organisation => [qw/ name employees /, company_number => [is => 'rw']],
Person => [qw/ name /];
my $alice = Person->new(name => 'Alice');
my $bob = Person->new(name => 'Bob');
my $acme = Organisation->new(name => 'ACME', employees => [$alice, $bob]);
note sprintf("Person class: %s", Person);
note sprintf("Organisation class: %s", Organisation);
is(
ref($alice),
ref($bob),
'Alice and Bob are in the same class',
);
isnt(
ref($alice),
ref($acme),
'Alice and ACME are not in the same class',
);
isa_ok($_, 'MooX::Struct', '$'.lc($_->name)) for ($alice, $bob, $acme);
is($alice->name, 'Alice', '$alice is called Alice');
is($bob->name, 'Bob', '$bob is called Bob');
is($acme->name, 'ACME', '$acme is called ACME');
ok !eval {
$acme->name('Acme Inc'); 1
}, 'accessors are read-only by default';
$acme->company_number(12345);
is($acme->company_number, 12345, 'accessors can be made read-write');
can_ok $alice => 'OBJECT_ID';
isnt($alice->OBJECT_ID, $bob->OBJECT_ID, 'OBJECT_ID is unique identifier');
03inherit.t 000664 001750 001750 4174 12404143766 14732 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that different structs can inherit from each other.
Check that the "-class" option works.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use Test::More;
use MooX::Struct
Agent => [ name => undef, -class => \'Local::Test::Class1' ],
Organisation => [ -extends => ['Agent'], employees => undef, company_number => [is => 'rw']],
Person => [ -extends => ['Agent'], -class => [qw/Local Test Class2/] ];
my $alice = Person->new(name => 'Alice');
my $bob = Person->new(name => 'Bob');
my $acme = Organisation->new(name => 'ACME', employees => [$alice, $bob]);
note sprintf("Agent class: %s", Agent);
note sprintf("Person class: %s", Person);
note sprintf("Organisation class: %s", Organisation);
is(Agent, 'Local::Test::Class1');
is(Person, 'Local::Test::Class2');
isa_ok($alice, 'Local::Test::Class1');
isa_ok($alice, 'Local::Test::Class2');
is(
ref($alice),
ref($bob),
'Alice and Bob are in the same class',
);
isnt(
ref($alice),
ref($acme),
'Alice and ACME are not in the same class',
);
isa_ok($_, 'MooX::Struct', '$'.lc($_->name)) for ($alice, $bob, $acme);
isa_ok($alice, Agent);
isa_ok($bob, Agent);
isa_ok($acme, Agent);
isa_ok($alice, Person);
isa_ok($bob, Person);
isa_ok($acme, Organisation);
isa_ok(Organisation, Agent);
isa_ok(Person, Agent);
is($alice->name, 'Alice', '$alice is called Alice');
is($bob->name, 'Bob', '$bob is called Bob');
is($acme->name, 'ACME', '$acme is called ACME');
ok !eval {
$acme->name('Acme Inc'); 1
}, 'accessors are read-only by default';
$acme->company_number(12345);
is($acme->company_number, 12345, 'accessors can be made read-write');
can_ok $alice => 'OBJECT_ID';
isnt($alice->OBJECT_ID, $bob->OBJECT_ID, 'OBJECT_ID is unique identifier');
use MooX::Struct XXX1 => [ qw< $foo > ];
use MooX::Struct XXX2 => [ -extends => [ XXX1 ], qw< $bar > ];
is_deeply([XXX2->FIELDS], [qw< foo bar >]);
done_testing;
04flag.t 000664 001750 001750 1221 12404143766 14170 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that the "-rw" flag works.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use Test::More tests => 1;
use MooX::Struct -rw,
Agent => [qw( name )],
Person => [ -extends => ['Agent'] ];
my $bob = Person->new(name => 'Bob');
note sprintf("Agent class: %s", Agent);
note sprintf("Person class: %s", Person);
$bob->name('Robert');
is($bob->name, 'Robert');
05methods.t 000664 001750 001750 1043 12404143766 14725 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that methods can be added to structs.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More tests => 1;
use MooX::Struct
Person => [
qw( name age sex ),
uc_name => sub {
my $self = shift;
return uc $self->name;
},
];
is(Person->new(name => 'Bob')->uc_name, 'BOB');
06sigils.t 000664 001750 001750 5261 12404143766 14563 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that the required (C<< ! >>) postfix sigil works, and that the
scalar ((C<< $ >>), array (C<< @ >>) and hash (C<< % >>) prefix sigils
work.
Check that the C<< + >> postfix sigil works, that numbers can default to
values other than zero, and that an explicit C works.
Make sure that sigils are just hints, and can be overridden by an explicit
attribute spec.
Checks that attribute specs can be hashrefs or arrayrefs.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
use Scalar::Does qw( does looks_like_number );
use MooX::Struct
Structure => [
qw( $value %dict @list ),
'@value2' => { isa => sub { die if ref $_[0] } },
'%list2' => [ isa => sub { die unless does $_[0], 'ARRAY' } ],
'$dict2' => [ isa => sub { die unless does $_[0], 'HASH' } ],
],
OtherStructure => [qw( id! ego )],
Point => ['+x', '+y' => [default => sub { 101 }]],
Point3D => [-extends => ['Point'], '+z' => [isa => sub { die unless looks_like_number($_[0]) || !defined $_[0] }]],
PointReq => ['+x!', '+y!'],
;
ok eval {
Structure->new( value => Structure->new )
};
ok eval {
Structure->new( value => 42 )
};
ok eval {
Structure->new( list => [] )
};
ok eval {
Structure->new( dict => +{} )
};
ok eval {
Structure->new( value2 => "Hello World" );
};
ok eval {
Structure->new( list2 => [] );
};
ok eval {
Structure->new( dict2 => {foo => 42} );
};
ok !eval {
Structure->new( value => [] )
};
ok !eval {
Structure->new( value => +{} )
};
ok !eval {
Structure->new( list => 42 )
};
ok !eval {
Structure->new( dict => 42 )
};
ok !eval {
Structure->new( value2 => [] );
};
ok !eval {
Structure->new( list2 => +{} );
};
ok !eval {
Structure->new( dict2 => 42 );
};
ok eval {
OtherStructure->new(id => undef);
};
ok !eval {
OtherStructure->new(ego => undef);
};
my $point = Point->new;
ok defined $point->x;
ok defined $point->y;
is($point->x, 0);
is($point->y, 101);
ok eval {
Point[ 42, 42 ];
Point[ 42.1, 42.2 ];
Point[ "99", "999" ];
Point[ "+Inf", "-Inf" ];
};
ok not eval {
Point[ "Hello", "World" ];
};
ok not eval {
Point[ "", "" ];
};
ok not eval {
Point[ "Hello", "99" ];
};
ok eval {
Point3D[ 1, 2 ];
Point3D[ 1, 2, 3 ];
Point3D[ 1, 2, undef ];
};
is_deeply(
Point3D->new->TO_ARRAY,
[ 0, 101, 0 ],
);
ok not eval {
Point3D[ 1, 2, "Hello" ];
};
ok eval {
PointReq[ 1, 2 ];
PointReq[ 0, '-Inf' ];
PointReq[ 0, 0 ];
};
ok not eval {
PointReq[ ];
};
ok not eval {
PointReq[ "abc", 0 ];
};
done_testing();
07overloading.t 000664 001750 001750 1537 12404143766 15605 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that overloading to string and to arrayref work.
Also checks the C method.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
use MooX::Struct
Point => [ qw(x y) ],
Point3D => [ -extends => [qw(Point)], qw(z) ],
;
my $point = Point->new(x => 3, y => 4);
is("$point", "3 4", "Point stringifies correctly");
my $point2 = Point3D->new(x => 3, y => 4, z => 5);
is("$point2", "3 4 5", "Point3D stringifies correctly");
is_deeply( [ @$point2 ], [qw(3 4 5)], "Point3D casts to array properly" );
my $clone = CLONE $point2;
is("$clone", "3 4 5", "cloning is awesome");
done_testing;
08alt-constructor.t 000664 001750 001750 2546 12404143766 16441 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check square-bracket-style constructor.
Also checks constructor called with a hashref (works, but not officially
supported).
Tests that objects overloading both hash and array are considered to be
hashrefs by the constructor, not arrayrefs.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
use MooX::Struct
Point => [ qw( +x +y ) ],
Point3D => [ -extends => [qw(Point)], qw( +z ) ],
;
my $point1 = Point[3, 4];
my $point2 = Point3D[3, 4, 5];
my $point3 = Point3D[3, 4];
is("$point1", "3 4");
is("$point2", "3 4 5");
is("$point3", "3 4 0");
is(
Point3D->new([3, 4, 5])->TO_STRING,
"3 4 5",
);
is(
Point3D->new({ z=>1, y=>2, x=>3, y=>4, z=>5 })->TO_STRING,
"3 4 5",
);
ok not eval {
Point3D->new( \*STDERR )
};
ok not eval {
Point3D[1, 2, 3, 4]
};
{
package Local::WeirdHash;
use overload '@{}' => 'TO_ARRAY';
sub TO_ARRAY {
my $self = shift;
[ sort keys %$self ];
}
}
my $weird = bless { z=>1, y=>2, x=>3, y=>4, z=>5 }, 'Local::WeirdHash';
is(
Point3D->new($weird)->TO_STRING,
"3 4 5",
'if constructed with an object that "does" array and hash, hash is preferred',
);
done_testing();
09roles.t 000664 001750 001750 1710 12404143766 14413 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that structs can consume Moo roles.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
BEGIN {
package Local::Role1;
use Moo::Role;
has attr1 => (is => 'ro');
}
BEGIN {
package Local::Role2;
use Moo::Role;
has attr2 => (is => 'ro');
}
use MooX::Struct
Thingy => [
-with => [qw( Local::Role2 Local::Role1 )],
qw/ $attr3 $attr4 /,
],
;
is_deeply(
[ Thingy->FIELDS ],
[ qw/ attr3 attr4 / ],
);
my $thingy = Thingy[qw/ 3 4 /];
#is($thingy->attr1, 1);
#is($thingy->attr2, 2);
is($thingy->attr3, 3);
is($thingy->attr4, 4);
$thingy = Thingy->new(map { ; "attr$_", $_ } 1..4);
is($thingy->attr1, 1);
is($thingy->attr2, 2);
is($thingy->attr3, 3);
is($thingy->attr4, 4);
done_testing;
10strict-constructor.t 000664 001750 001750 1124 12404143766 17151 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that the constructor is strict (throws an error if it sees unknown
attributes).
This test is currently disabled, as the constructor is no longer strict.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More skip_all => 'no longer valid';
use MooX::Struct Thingy => [qw/ $x /];
ok not eval { my $thingy = Thingy->new(y => 1) };
11extend.t 000664 001750 001750 3621 12404143766 14552 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check the experimental C method.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
use MooX::Struct Point => [qw( +x +y )];
my $point = Point[];
my $old_id = $point->OBJECT_ID;
is($point->TYPE, 'Point');
is_deeply([$point->FIELDS], ['x', 'y']);
ok( $point->can('x'));
ok( $point->can('y'));
ok(!$point->can('z'));
$point->EXTEND(\"Point3D", '+z');
is($point->TYPE, 'Point3D');
is_deeply([$point->FIELDS], ['x', 'y', 'z']);
ok( $point->can('x'));
ok( $point->can('y'));
ok( $point->can('z'));
is($point->OBJECT_ID, $old_id, 'OBJECT_ID does not change during EXTEND');
my $new = $point->CLONE(z => 0)->EXTEND(\"Point4D", '+w');
is_deeply([$point->FIELDS], ['x', 'y', 'z']);
is_deeply([$new->FIELDS], ['x', 'y', 'z', 'w']);
isnt($new->OBJECT_ID, $old_id, 'OBJECT_ID does change during CLONE+EXTEND');
use MooX::Struct Person => ['$name'];
my $Employee = Person->EXTEND(\"Employee", '$title');
isa_ok($Employee, Person);
my $bob = $Employee->new(['Robert', 'Staff']);
isa_ok($bob, $Employee);
isa_ok($bob, Person);
is($bob->TYPE, 'Employee');
is_deeply([$bob->FIELDS], [qw/ name title /]);
is($bob->name, 'Robert');
is($bob->title, 'Staff');
ok !eval { $bob->title('Manager') }; # read-only
my $PromotableEmployee = Person->EXTEND(-rw, \"PromotableEmployee", '$title');
isa_ok($PromotableEmployee, Person);
my $alice = $PromotableEmployee->new(['Alice', 'Staff']);
isa_ok($alice, $PromotableEmployee);
isa_ok($alice, Person);
is($alice->TYPE, 'PromotableEmployee');
is_deeply([$alice->FIELDS], [qw/ name title /]);
is($alice->name, 'Alice');
is($alice->title, 'Staff');
$alice->title('Manager'); # read-write
is($alice->title, 'Manager');
done_testing;
12lexical.t 000664 001750 001750 1723 12404143766 14706 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check that struct aliases are lexical, but can be made permanent
using the C<< -retain >> flag.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
{
package Local::Foo1;
use MooX::Struct
Bar => [qw($name)],
;
::ok(
Bar->can('name'),
'Bar class available inside Local::Foo1',
);
}
{
package Local::Foo2;
use MooX::Struct -retain,
Bar => [qw($name)],
;
::ok(
Bar->can('name'),
'Bar class available inside Local::Foo2',
);
}
::ok(
!'Local::Foo1'->can('Bar'),
"Bar class unavailable outside Local::Foo1",
);
::ok(
'Local::Foo2'->can('Bar'),
"Bar class available outside Local::Foo2",
);
::ok(
Local::Foo2::Bar->can('name'),
"Bar class works outside Local::Foo2",
);
done_testing;
13basestruct.t 000664 001750 001750 1027 12404143766 15442 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Checks that MooX::Struct itself can be instantiated and works as expected.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use Test::More;
use MooX::Struct;
my $obj = MooX::Struct->new;
is($obj->TYPE, undef);
is_deeply([$obj->FIELDS], []);
done_testing;
14trace.t 000664 001750 001750 3456 12404143766 14372 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Tests the output of the "-trace" feature.
Checks that the C environment variable is honoured.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use if ($] < 5.010), 'Test::More', skip_all => 'need Perl 5.10';
use Test::More;
use 5.010;
use MooX::Struct ();
use IO::Handle;
my $default = "MooX::Struct::Processor"->new(trace => 1);
is($default->trace_handle, \*STDERR);
my $output;
open my $handle, '>', \$output;
my $proc = "MooX::Struct::Processor"->new(trace => 1, trace_handle => $handle);
$proc->process(
__PACKAGE__,
Something => ['$foo', announce_foo => sub { say shift->foo } ],
);
my $obj = new_ok Something(), [[1]];
is($output, <<"EXPECTED");
package @{[ Something() ]};
use Moo;
has foo => ('is' => 'ro','isa' => sub { "DUMMY" });
sub announce_foo { ... }
sub FIELDS { ... }
sub TYPE { ... }
EXPECTED
$output = '';
BEGIN {
package Local::Role;
use Moo::Role;
requires 'foo';
};
$proc->flags->{deparse} = 1;
$proc->process(
__PACKAGE__,
SomethingElse => [
-class => \'Something::Else',
-isa => [Something()],
-with => ['Local::Role'],
announce_foo => sub { my $self = shift; print $self->foo, "\n" },
'+number', 'random',
],
);
$obj = new_ok SomethingElse(), [[1]];
like($output, qr{package Something::Else});
like($output, qr{with qw.Local::Role.});
like($output, qr{print \$self->foo});
like($output, qr{looks_like_number});
{
local $ENV{PERL_MOOX_STRUCT_TRACE} = 1;
ok "MooX::Struct::Processor"->new->trace;
}
ok not "MooX::Struct::Processor"->new->trace;
done_testing;
96processor.t 000664 001750 001750 1345 12404143766 15320 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Checks some places where MooX::Struct::Processor is expected to fail.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use Test::More;
use MooX::Struct ();
ok not eval {
"MooX::Struct::Processor"->new(flags => 1);
};
ok not eval {
"MooX::Struct::Processor"->new(class_map => 1);
};
ok not eval {
"MooX::Struct::Processor"->new->process(
__PACKAGE__,
Foo => [ -monkey => ['Albert'] ],
);
Foo();
};
like($@, qr{option '-monkey' unknown});
done_testing;
97dataprinter.t 000664 001750 001750 2031 12404143766 15610 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Test Data::Printer support for structs.
Skipped if Data::Printer is not installed.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use if !eval{ require Data::Printer },
'Test::More', skip_all => 'need Data::Printer';
use Test::More;
use Data::Printer colored => 0;
use MooX::Struct Something => [qw( $foo bar )];
my $obj = Something->new(foo => 1, bar => 2);
my $str = p $obj;
is($str, 'Something[ 1, 2 ]');
my $ob2 = Something->new(foo => "Hello\nWorld", bar => ["A","B\nC","D"]);
my $st2 = p $ob2;
like("$st2\n", qr{^Something\[\n}s, 'dump including line breaks');
my $ext = Something->EXTEND('$baz')->new([1, 2, 3]);
my $pxt = p $ext;
is($pxt, 'Something[ 1, 2, 3 ]');
my $bas = MooX::Struct->new;
my $pas = p $bas;
is($pas, 'struct[ ]');
done_testing;
98baseclass.t 000664 001750 001750 3520 12404143766 15240 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Tests that a MooX::Struct::Processor, configured with a base class
that has some attributes, will generate structs that are aware of
those attributes (shows them in C).
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use Test::More;
use MooX::Struct Foo => ['$foo'];
BEGIN {
"MooX::Struct::Processor"
-> new(
base => Foo,
flags => { retain => 1 },
)
-> process(
main => (
Bar => ['$bar'],
Baz => ['$baz', -class => \'Baz'],
),
)
;
};
is_deeply(
[ Foo->FIELDS ],
[ qw( foo ) ],
);
isa_ok(Bar, Foo);
is_deeply(
[ Bar->FIELDS ],
[ qw( foo bar ) ],
);
isa_ok(Baz, Foo);
is_deeply(
[ Baz->FIELDS ],
[ qw( foo baz ) ],
);
my $bar = Bar[1, 2];
is($bar->foo, 1);
is($bar->bar, 2);
# The "interesting" thing about this package is that it provides
# no FIELDS method.
BEGIN {
package Quux;
use Moo;
has bumf => (is => 'rw');
};
BEGIN {
"MooX::Struct::Processor"
-> new(
base => 'Quux',
flags => { retain => 1 },
)
-> process(
main => (
Quuux => ['$xyzzy'],
Quuuux => (),
),
)
;
};
my $quuux = Quuux->new(xyzzy => 4, bumf => 2);
is_deeply([$quuux->FIELDS], ['xyzzy']);
is($quuux->xyzzy, 4);
is($quuux->bumf, 2);
like(ref $quuux, qr{^Quux::__ANON__::});
my $quuuux = Quuuux->new(bumf => 2);
is_deeply([$quuuux->FIELDS], []);
is($quuuux->bumf, 2);
like(ref $quuuux, qr{^Quux::__ANON__::});
BEGIN {
"MooX::Struct::Processor"
-> new(
flags => { retain => 1 },
)
-> process(
main => (
Quux2 => [ -extends=>['Quux'], '$xyzzy' ],
),
)
;
};
is_deeply([Quux2->FIELDS], ['xyzzy']);
done_testing;
99lazy.t 000664 001750 001750 1147 12404143766 14263 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 PURPOSE
Check C from C.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test::More;
use MooX::Struct::Util qw/ lazy_default /;
use MooX::Struct Point => [ '+x', '+y' ];
use MooX::Struct Line => [ '$start' => lazy_default { Point[] }, '$end' ];
my $line = Line->new( end => Point[ 2, 3 ] );
is("$line", "0 0 2 3");
done_testing(); readme.pod 000664 001750 001750 220 12404143766 14645 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/t =head1 TEST COVERAGE
As of 0.010, according to L the test coverage for
L and L is 100%.
=cut
Struct.pm 000664 001750 001750 44775 12404143766 16002 0 ustar 00tai tai 000000 000000 MooX-Struct-0.013/lib/MooX package MooX::Struct;
use 5.008;
use strict;
use warnings;
use utf8;
BEGIN {
$MooX::Struct::AUTHORITY = 'cpan:TOBYINK';
$MooX::Struct::VERSION = '0.013';
}
use Moo 1.000000;
use Object::ID 0 qw( );
use Scalar::Does 0 qw( does );
use overload
q[""] => 'TO_STRING',
q[bool] => sub { 1 },
q[@{}] => 'TO_ARRAY',
q[=] => 'CLONE',
fallback => 1;
METHODS: {
no warnings;
sub OBJECT_ID { goto \&Object::ID::object_id };
sub FIELDS { qw() };
sub TYPE { +undef };
sub TO_ARRAY { [ map {; $_[0]->$_ } $_[0]->FIELDS ] };
sub TO_HASH { +{ map {; $_ => $_[0]->$_ } $_[0]->FIELDS } };
sub TO_STRING { join q[ ], @{ $_[0]->TO_ARRAY } };
sub CLONE { my $s = shift; ref($s)->new(%{$s->TO_HASH}, @_) };
};
sub BUILDARGS
{
my $class = shift;
my @fields = $class->FIELDS;
if (
@_ == 1 and
does($_[0], 'ARRAY') and
not does($_[0], 'HASH')
)
{
my @values = @{ $_[0] };
Carp::confess("too many values passed to constructor (expected @fields); stopped")
unless @fields >= @values;
no warnings;
return +{
map {
$fields[$_] => $values[$_];
} 0 .. $#values
}
}
elsif (@_ == 1 and does($_[0], 'HASH') and not ref($_[0]) eq 'HASH')
{
# help Moo::Object!
@_ = +{ %{$_[0]} };
}
my $hashref = $class->SUPER::BUILDARGS(@_);
# my %tmp = map { $_ => 1 } keys %$hashref;
# delete $tmp{$_} for @fields;
# if (my @unknown = sort keys %tmp)
# {
# Carp::confess("unknown keys passed to constructor (@unknown); stopped");
# }
return $hashref;
}
sub EXTEND
{
my ($invocant, @args) = @_;
my $base = $invocant;
$base = ref $invocant if ref $invocant;
my $processor = 'MooX::Struct::Processor'->new;
while (@args) {
last unless $args[0] =~ /^-(.+)$/;
$processor->flags->{ lc($1) } = !!shift @args;
}
my $subname = undef;
$subname = ${ shift @args } if ref($args[0]) eq 'SCALAR';
my $new_class = $processor->make_sub(
$subname,
[ -extends => [$base], @args ],
)->();
return $new_class unless ref $invocant;
bless $invocant => $new_class;
}
# This could do with some improvement from a Data::Printer expert.
#
my $done = 0;
sub _data_printer
{
require Data::Printer::Filter;
require Term::ANSIColor;
my $self = shift;
my @values = map { scalar &Data::Printer::p(\$_) } @$self;
my $label = Term::ANSIColor::colored($self->TYPE||'struct', 'bright_yellow');
if (grep /\n/, @values)
{
return sprintf(
"%s[\n\t%s,\n]",
$label,
join(qq[,\n\t], map { s/\n/\n\t/gm; $_ } @values),
);
}
sprintf('%s[ %s ]', $label, join q[, ], @values);
}
BEGIN {
package MooX::Struct::Processor;
{
no warnings;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.013';
}
sub _uniq { my %seen; grep { not $seen{$_}++ } @_ };
use Moo 1.000000;
use Carp 0 qw( confess );
use Data::OptList 0 qw( );
use Sub::Install 0 qw( install_sub );
use Scalar::Does 0 qw( does blessed looks_like_number );
use namespace::clean qw( );
use B::Hooks::EndOfScope qw( on_scope_end );
has flags => (
is => 'ro',
isa => sub { die "flags must be HASH" unless does $_[0], 'HASH' },
default => sub { +{} },
);
has class_map => (
is => 'ro',
isa => sub { die "class_map must be HASH" unless does $_[0], 'HASH' },
default => sub { +{} },
);
has base => (
is => 'ro',
default => sub { 'MooX::Struct' },
);
has trace => (
is => 'lazy',
);
sub _build_trace
{
$ENV{PERL_MOOX_STRUCT_TRACE}
or shift->flags->{trace};
}
has trace_handle => (
is => 'lazy',
);
sub _build_trace_handle
{
require IO::Handle;
\*STDERR;
}
my $counter = 0;
sub create_class
{
my ($self, $opts) = @_;
my $klass;
for my $o (@$opts) {
next unless $o->[0] eq '-class';
$klass = ref($o->[1]) eq 'ARRAY' ? join('::', @{$o->[1]}) : ${$o->[1]};
last;
}
$klass = sprintf('%s::__ANON__::%04d', $self->base, ++$counter) unless defined $klass;
"Moo"->_set_superclasses($klass, $self->base);
"Moo"->_maybe_reset_handlemoose($klass);
if ($self->trace)
{
$self->trace_handle->printf(
"package %s;\nuse Moo;\n",
$klass,
);
}
return $klass;
}
sub process_meta
{
my ($self, $klass, $name, $val) = @_;
if ($name eq '-extends' or $name eq '-isa')
{
my @parents = map {
exists $self->class_map->{$_}
? $self->class_map->{$_}->()
: $_
} @$val;
"Moo"->_set_superclasses($klass, @parents);
"Moo"->_maybe_reset_handlemoose($klass);
if ($self->trace)
{
$self->trace_handle->printf(
"extends qw(%s)\n",
join(q[ ] => @parents),
);
}
return map { $_->can('FIELDS') ? $_->FIELDS : () } @parents;
}
elsif ($name eq '-with')
{
require Moo::Role;
"Moo::Role"->apply_roles_to_package($klass, @$val);
"Moo"->_maybe_reset_handlemoose($klass);
if ($self->trace)
{
$self->trace_handle->printf(
"with qw(%s)\n",
join(q[ ] => @$val),
);
}
return
# map { my $role = $_; grep { not ref $_ } @{ $Moo::Role::INFO{$role}{attributes} } }
# @$val;
}
elsif ($name eq '-class')
{
# skip; already handled by 'create_class' method (hopefully)
}
else
{
confess("option '$name' unknown");
}
return;
}
sub process_method
{
my ($self, $klass, $name, $coderef) = @_;
install_sub {
into => $klass,
as => $name,
code => $coderef,
};
if ($self->trace)
{
$self->trace_handle->printf(
"sub %s { ... }\n",
$name,
);
if ($self->flags->{deparse})
{
require B::Deparse;
my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($coderef);
$code =~ s/^/# /mig;
$self->trace_handle->printf("$code\n");
}
}
return;
}
sub process_spec
{
my ($self, $klass, $name, $val) = @_;
my %spec = (
is => ($self->flags->{rw} ? 'rw' : 'ro'),
( does($val, 'ARRAY')
? @$val
: ( does($val,'HASH') ? %$val : () )
),
);
if ($name =~ /^(.+)\!$/)
{
$name = $1;
$spec{required} = 1;
}
if ($name =~ /^\@(.+)/)
{
$name = $1;
$spec{isa} ||= sub {
die "wrong type for '$name' (not arrayref)"
unless does($_[0], 'ARRAY');
};
}
elsif ($name =~ /^\%(.+)/)
{
$name = $1;
$spec{isa} ||= sub {
die "wrong type for '$name' (not hashref)"
unless does($_[0], 'HASH');
};
}
elsif ($name =~ /^\+(.+)/)
{
$name = $1;
$spec{isa} ||= sub {
die "wrong type for '$name' (not number)"
unless looks_like_number($_[0]);
};
$spec{default} ||= sub { 0 } unless $spec{required};
}
elsif ($name =~ /^\$(.+)/)
{
$name = $1;
$spec{isa} ||= sub {
my $ref = ref($_[0]);
die "wrong type for '$name' (should not be arrayref or hashref)"
if $ref eq 'ARRAY' || $ref eq 'HASH';
};
}
return ($name, \%spec);
}
sub process_attribute
{
my ($self, $klass, $name, $val) = @_;
my $spec;
($name, $spec) = $self->process_spec($klass, $name, $val);
if ($self->trace)
{
require Data::Dumper;
my $spec_str = "Data::Dumper"->new([$spec])->Terse(1)->Indent(0)->Sortkeys(1)->Dump;
$spec_str =~ s/(^\{)|(\}$)//g;
$self->trace_handle->printf(
"has %s => (%s);\n",
$name,
$spec_str,
);
if ($self->flags->{deparse} and $spec->{isa})
{
require B::Deparse;
my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($spec->{isa});
$code =~ s/^/# /mig;
$self->trace_handle->printf("$code\n");
}
}
"Moo"
->_constructor_maker_for($klass)
->register_attribute_specs($name, $spec);
"Moo"
->_accessor_maker_for($klass)
->generate_method($klass, $name, $spec);
"Moo"
->_maybe_reset_handlemoose($klass);
return $name;
}
# returns a list of "fields" resulting from the argument
sub process_argument
{
my $self = shift;
my ($klass, $name, $val) = @_;
return $self->process_meta(@_) if $name =~ /^-/;
return $self->process_method(@_) if does($val, 'CODE');
return $self->process_attribute(@_);
}
sub make_sub
{
my ($self, $subname, $proto) = @_;
return sub (;$)
{
1; # bizarre, but necessary if $] < 5.014
if (ref $proto) # inflate!
{
my $opts = Data::OptList::mkopt($proto);
my $klass = $self->create_class($opts);
my $seen_extends;
my @fields = _uniq map {
++$seen_extends if $_->[0] eq '-extends';
$self->process_argument($klass, @$_);
} @$opts;
unshift @fields, $self->base->FIELDS
if !$seen_extends && $self->base->can('FIELDS');
$self->process_method($klass, FIELDS => sub { @fields });
$self->process_method($klass, TYPE => sub { $subname }) if defined $subname;
$proto = $klass;
}
return $proto->new(@_) if @_;
return $proto;
}
}
sub process
{
my $self = shift;
my $caller = shift;
while (@_ and $_[0] =~ /^-(.+)$/) {
$self->flags->{ lc($1) } = !!shift;
}
foreach my $arg (@{ Data::OptList::mkopt(\@_) })
{
my ($subname, $details) = @$arg;
$details = [] unless defined $details;
$self->class_map->{ $subname } = $self->make_sub($subname, $details);
install_sub {
into => $caller,
as => $subname,
code => $self->class_map->{ $subname },
};
}
on_scope_end {
namespace::clean->clean_subroutines(
$caller,
keys %{ $self->class_map },
);
} unless $self->flags->{ retain };
}
};
sub import
{
my $caller = caller;
my $class = shift;
"$class\::Processor"->new->process($caller, @_);
}
no Moo;
1;
__END__
=head1 NAME
MooX::Struct - make simple lightweight record-like structures that make sounds like cows
=head1 SYNOPSIS
use MooX::Struct
Point => [ 'x', 'y' ],
Point3D => [ -extends => ['Point'], 'z' ],
;
my $origin = Point3D->new( x => 0, y => 0, z => 0 );
# or...
my $origin = Point3D[ 0, 0, 0 ];
=head1 DESCRIPTION
MooX::Struct allows you to create cheap struct-like classes for your data
using L.
While similar in spirit to L and L,
MooX::Struct has a somewhat different usage pattern. Rather than providing
you with a C keyword which can be used to define structs, you
define all the structs as part of the C