COPYRIGHT000664001750001750 372114260555033 13603 0ustar00taitai000000000000Role-Hooks-0.008Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Role-Hooks Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/Role-Hooks Files: Changes META.json META.yml doap.ttl t/07mite.t t/30inflate.t t/99nonrole.t t/mite/lib/Local/Class1.pm t/mite/lib/Local/Class1.pm.mite.pm t/mite/lib/Local/Role1.pm t/mite/lib/Local/Role1.pm.mite.pm t/mite/lib/Local/Role2.pm t/mite/lib/Local/Role2.pm.mite.pm Copyright: Copyright 2022 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: Makefile.PL dist.ini t/02roletiny.t t/03moorole.t t/04mooserole.t t/05mouserole.t t/06rolebasic.t t/10moorole_in_moose.t t/11mooserole_in_moo.t Copyright: Copyright 2020 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: INSTALL LICENSE t/mite/.mite/config Copyright: Unknown License: Unknown Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: README lib/Role/Hooks.pm Copyright: This software is copyright (c) 2020-2022 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/20packagevariant.t Copyright: This software is copyright (c) 2022 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/01basic.t Copyright: This software is copyright (c) 2020 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/mite/lib/Local/Mite.pm Copyright: This software is copyright (c) 2011-2014 by Michael G Schwern. This software is copyright (c) 2022 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/rt-133595.t Copyright: This software is copyright (c) 2020 by Gianni Ceccarelli. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2022 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) 2022 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 36514260555033 13311 0ustar00taitai000000000000Role-Hooks-0.008Maintainer: - Toby Inkster (TOBYINK) Thanks: - Alexander Hartmaier (ABRAXXA) - Gianni Ceccarelli (DAKKAR) - Graham Knop (HAARG) - Tina Müller (TINITA) Changes000664001750001750 236014260555033 13601 0ustar00taitai000000000000Role-Hooks-0.008Role-Hooks ========== Created: 2020-02-18 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.008 2022-07-04 [ Bug Fixes ] - Fix accidental dependency on Role::Tiny. Tina Müller++ 0.007 2022-07-04 [ Bug Fixes ] - Eliminate 'used only once' warnings. Alexander Hartmaier++ [ Test Suite ] - Include a test that a known non-role returns false from is_role. 0.006 2022-07-01 - Updated: Support for roles built using Mite. 0.005 2022-06-17 - Added: Add after_inflate hook. 0.004 2022-06-07 [ Bug Fixes ] - Add missing `print` to print statements in examples. Fixes RT#135361. Alexander Hartmaier++ [ Documentation ] - Test and document interaction with Package::Variant. 0.003 2020-10-26 [ Bug Fixes ] - Stop polluting Role::Tiny namespace. Graham Knop++ 0.002 2020-10-23 [ Bug Fixes ] - Died applying a role to a non-Moo* class, with Moose loaded. Fixes RT#133595. Gianni Ceccarelli++ 0.001 2020-02-18 Initial release INSTALL000664001750001750 166014260555033 13341 0ustar00taitai000000000000Role-Hooks-0.008 Installing Role-Hooks should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm Role::Hooks 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 Role::Hooks INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Role::Hooks 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 Role-Hooks: % 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 LICENSE000664001750001750 4365514260555033 13347 0ustar00taitai000000000000Role-Hooks-0.008This software is copyright (c) 2022 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) 2022 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) 2022 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 MANIFEST000664001750001750 107314260555033 13437 0ustar00taitai000000000000Role-Hooks-0.008COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README SIGNATURE dist.ini doap.ttl lib/Role/Hooks.pm t/01basic.t t/02roletiny.t t/03moorole.t t/04mooserole.t t/05mouserole.t t/06rolebasic.t t/07mite.t t/10moorole_in_moose.t t/11mooserole_in_moo.t t/20packagevariant.t t/30inflate.t t/99nonrole.t t/mite/.mite/config t/mite/lib/Local/Class1.pm t/mite/lib/Local/Class1.pm.mite.pm t/mite/lib/Local/Mite.pm t/mite/lib/Local/Role1.pm t/mite/lib/Local/Role1.pm.mite.pm t/mite/lib/Local/Role2.pm t/mite/lib/Local/Role2.pm.mite.pm t/rt-133595.t META.json000664001750001750 420514260555033 13727 0ustar00taitai000000000000Role-Hooks-0.008{ "abstract" : "role callbacks", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 0, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "keywords" : [], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Role-Hooks", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "develop" : { "recommends" : { "Dist::Inkt" : "0.001" } }, "runtime" : { "requires" : { "Class::Method::Modifiers" : "0", "List::Util" : "1.45", "perl" : "5.008001" } }, "test" : { "recommends" : { "Class::Tiny" : "0", "Moo::Role" : "0", "Moose::Role" : "0", "Role::Tiny" : "0" }, "requires" : { "Test::More" : "0.96", "Test::Requires" : "0" }, "suggests" : { "Mouse::Role" : "0", "Role::Basic" : "0" } } }, "provides" : { "Role::Hooks" : { "file" : "lib/Role/Hooks.pm", "version" : "0.008" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/tobyink/p5-role-hooks/issues" }, "homepage" : "https://metacpan.org/release/Role-Hooks", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-role-hooks.git", "web" : "https://github.com/tobyink/p5-role-hooks" }, "x_identifier" : "http://purl.org/NET/cpan-uri/dist/Role-Hooks/project" }, "version" : "0.008", "x_serialization_backend" : "JSON::PP version 4.09", "x_static_install" : 1 } META.yml000664001750001750 207514260555033 13562 0ustar00taitai000000000000Role-Hooks-0.008--- abstract: 'role callbacks' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::More: '0.96' Test::Requires: '0' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010' keywords: [] license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Role-Hooks no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: Role::Hooks: file: lib/Role/Hooks.pm version: '0.008' requires: Class::Method::Modifiers: '0' List::Util: '1.45' perl: '5.008001' resources: Identifier: http://purl.org/NET/cpan-uri/dist/Role-Hooks/project bugtracker: https://github.com/tobyink/p5-role-hooks/issues homepage: https://metacpan.org/release/Role-Hooks license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-role-hooks.git version: '0.008' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_static_install: 1 Makefile.PL000664001750001750 1121714260555033 14301 0ustar00taitai000000000000Role-Hooks-0.008use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "role callbacks", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 0, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "keywords" => [], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "Role-Hooks", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, develop => { recommends => { "Dist::Inkt" => 0.001 } }, runtime => { requires => { "Class::Method::Modifiers" => 0, "List::Util" => 1.45, "perl" => 5.008001, }, }, test => { recommends => { "Class::Tiny" => 0, "Moo::Role" => 0, "Moose::Role" => 0, "Role::Tiny" => 0 }, requires => { "Test::More" => 0.96, "Test::Requires" => 0 }, suggests => { "Mouse::Role" => 0, "Role::Basic" => 0 }, }, }, "provides" => { "Role::Hooks" => { file => "lib/Role/Hooks.pm", version => 0.008 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "https://github.com/tobyink/p5-role-hooks/issues" }, homepage => "https://metacpan.org/release/Role-Hooks", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-role-hooks.git", web => "https://github.com/tobyink/p5-role-hooks", }, x_identifier => "http://purl.org/NET/cpan-uri/dist/Role-Hooks/project", }, "version" => 0.008, "x_static_install" => 1, }; 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; } } my $mm = WriteMakefile(%WriteMakefileArgs); exit(0); README000664001750001750 1365414260555033 13216 0ustar00taitai000000000000Role-Hooks-0.008NAME Role::Hooks - role callbacks SYNOPSIS package Local::Role { use Moo::Role; use Role::Hooks; Role::Hooks->after_apply(__PACKAGE__, sub { my ($role, $target) = @_; print "$role has been applied to $target.\n"; }); } package Local::Class { use Moo; with "Local::Role"; # prints above message } DESCRIPTION This module allows a role to run a callback when it is applied to a class or to another role. Compatibility It should work with Role::Tiny, Moo::Role, Moose::Role, Mouse::Role, Role::Basic, and Mite. Not all class builders work well with all role builders (for example, a Moose class consuming a Mouse role). But when they do work together, Role::Hooks should be able to run the callbacks. (The only combination I've tested is Moo with Moose though.) Some other role implementations (such as Moos::Role, exact::role, and OX::Role) are just wrappers around one of the supported role builders, so should mostly work. With Role::Basic, the `after_apply` hook is called a little earlier than would be ideal; after the role has been fully loaded and its methods have been copied into the target package, but before handling `requires`, and before patching the `DOES` method in the target package. If you are using Role::Basic, consider switching to Role::Tiny. With Mite, the `before_apply` hook is called fairly late; after the role is fully loaded and attributes and methods have been copied into the target package, after `DOES` has been patched, but before method modifiers from the role have been applied to the target package. Apart from Role::Tiny/Moo::Role, a hashref of additional arguments (things like "-excludes" and "-alias") can be passed when consuming a role. Although I discourage people from using these in general, if you need access to these arguments in the callback, you can check %Role::Hooks::ARGS. Roles generated via Package::Variant should work; see t/20packagevariant.t for a demonstration. Methods `before_apply` Role::Hooks->before_apply($rolename, $callback); Sets up a callback for a role that will be called before the role is applied to a target package. The callback will be passed two parameters: the role being applied and the target package. The role being applied may not be the same role as the role the callback was defined in! package Local::Role1 { use Moo::Role; use Role::Hooks; Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; print "$role has been applied to $target.\n"; }); } package Local::Role2 { use Moo::Role; with "Local::Role1"; } package Local::Class1 { use Moo::Role; with "Local::Role2"; } This will print: Local::Role1 has been applied to Local::Role2. Local::Role2 has been applied to Local::Class1. If you only care about direct applications of roles (i.e. the first one): Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; return if $role ne __PACKAGE__; print "$role has been applied to $target.\n"; }); If you only care about roles being applied to classes (i.e. the second one): Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; return if Role::Hooks->is_role($target); print "$role has been applied to $target.\n"; }); `after_apply` Role::Hooks->after_apply($rolename, $callback); The same as `before_apply`, but called later in the role application process. Note that when the callback is called, even though it's after the role has been applied to the target, it doesn't mean the target has finished being built. For example, there might be `has` statements after the `with` statement, and those will not have been evaluated yet. If you want to throw an error when someone applies your role to an inappropriate target, it is probably better to do that in `before_apply` if you can. `after_inflate` Role::Hooks->after_inflate($pkg_name, $callback); Even though this is part of Role::Hooks, it works on classes too. But it only works on classes and roles built using Moo. This runs your callback if your Moo class or role gets "inflated" to a Moose class or role. If you set up a callback for a role, then the callback will also get called if any packages that role was applied to get inflated. `is_role` Will return true if the given package seems to be a role, false otherwise. (In fact, returns a string representing which role builder the role seems to be using -- "Role::Tiny", "Moose::Role", "Mouse::Role", "Role::Basic", or "Mite::Role"; roles built using Moo::Role are detected as "Role::Tiny".) ENVIRONMENT The environment variable `PERL_ROLE_HOOKS_DEBUG` may be set to true to enable debugging messages. BUGS Please report any bugs to . SEE ALSO Role::Tiny, Moose::Role. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE This software is copyright (c) 2020-2022 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. SIGNATURE000664001750001750 723714260555033 13602 0ustar00taitai000000000000Role-Hooks-0.008This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.87. 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: RIPEMD160 SHA256 d7fd222ca29cfb76fd4148e5e497aa0df83454a49ef7a1222e8b746d0514bf98 COPYRIGHT SHA256 b1eb32301b48ce0a356bf5c19860addc7fee3eedda3652dd9dea5e0e5edc92db CREDITS SHA256 21a06955077ec9653da50c17f67e092956b3e0ccb9f26ded1901efd1d01a0c7e Changes SHA256 84cda7187b6db6480c7f829b6f7e4bc334ad80e599015d1b2d51fc9fb791f388 INSTALL SHA256 a4f85c6f4d6e8bdd37b7ab08013e3e3bee1fe8e910e20f8f54d5025ffe40f384 LICENSE SHA256 4c5043bdfb181995d654c13a30d9ea98bb9fe8b4a4735188626ed415e0f22c20 MANIFEST SHA256 fa2086bd47ca82b428462bbacaad7a5176aad015f5135513837bf3826f14afff META.json SHA256 794c3e74c1b4cc5107c04e6ce75508a73b191511f57d1bfc73bff5040e402fdf META.yml SHA256 135fb168284b8f939c8781a55a564d87b99663b371f838f6ded6fa766664bfae Makefile.PL SHA256 a846cee2ac36a308dc9481ff015f24ef7b10e8ccbebf467ca90e9604766141f8 README SHA256 f79a07917c7b78ecb9c1676269559deacb39ce459cd0788e979b0173e323d056 dist.ini SHA256 27f1a8bc5c4ccb54b7773f734a646e9717e74b5ece3b0b686690d4f940f8edcf doap.ttl SHA256 7780460e004bf47a4a48fb065b6bb3c569cff7c56664d08d86120f7aa1a52e3e lib/Role/Hooks.pm SHA256 fabc42d4abf7adc2c10aba206ee5bee8fcf76e591029a13c1238b55804597281 t/01basic.t SHA256 b764eb562984d138c3155db66bc92fcae3165057d4a61679635e730bb4e520e0 t/02roletiny.t SHA256 2e5c5eecb630941e533f31ee36f06e6a796c34bdbfee8abed956326cb901535b t/03moorole.t SHA256 29f1c125be1398ba7895ba166f8fb1335b5ec4c4f50a67f1a8bd5c4f4f87efa5 t/04mooserole.t SHA256 99d12cf7bd00e4d8df0630b54e23f654c3288e478766967c6b658e3e3cb70966 t/05mouserole.t SHA256 49f2e5629a9c867672e30defe9340e4deb7a2be5d13b4b0497484bf84f9691bc t/06rolebasic.t SHA256 f65a27d9ae5f551e35ad6c197ca92a34e2c3bff6c4de11c927c8451eb2f7839c t/07mite.t SHA256 593be63942e8e3a417f51ca82933070cdb56d93e0fe7d9ba11c2f6844ceacd1e t/10moorole_in_moose.t SHA256 f8f299ae1a9f2e69c4439f9acf6da50eb79b572a9c70172925db5034de7c50ce t/11mooserole_in_moo.t SHA256 b2e4b589a1ca0d708adcc2fa597a3c2365d0a469d9fe9a90826a1dbf88122414 t/20packagevariant.t SHA256 a913f2e394264b6f74985129c450479a8cba3e241cbe1dd0034e7eb0f37ddfba t/30inflate.t SHA256 1c985ee0886740c5a0a4bec0f09fdffefbf7250fe1529814981a5ddd9ab536d9 t/99nonrole.t SHA256 ed268e757ae107df338fe1b40d7e1cbbb7292a2cf8bc6a3e0b7fe62f48c68e02 t/mite/.mite/config SHA256 c7d9b71865f616a7c69603c5f4c661cadb8946fdca56b3ba347b795652d3c9b1 t/mite/lib/Local/Class1.pm SHA256 7d0c810bc21fba13105e788354fabcc632a2dc37a460ddad0cbedbdfb631e5db t/mite/lib/Local/Class1.pm.mite.pm SHA256 9c28906964c5cdaa720840f438c7c504db6728cab6f480d6916b8db6a5e9307b t/mite/lib/Local/Mite.pm SHA256 3332145aea6d0ade4e5a1476f85c01ee9ef31b13459aadcccdf2c220a9bf9b26 t/mite/lib/Local/Role1.pm SHA256 f0cc3efda852333e478f4731aa870d30b24ae5702da1d15ac5128cda9a8e3a35 t/mite/lib/Local/Role1.pm.mite.pm SHA256 372ed5021cab0ef3b0cf296103553a7a98ac9fc331d8e2505fa442ff9fd0c939 t/mite/lib/Local/Role2.pm SHA256 c8e0d29773f934c5878e59e7ec1b9782c5bf61fbc32da3d9574551ba91b8217e t/mite/lib/Local/Role2.pm.mite.pm SHA256 66c88d882d3f84bfc9a0e486a2a555369e1a1d6930e920a24f0d819064c4eada t/rt-133595.t -----BEGIN PGP SIGNATURE----- iF0EAREDAB0WIQRVJKj/4+s6z4WzNujOv4Eoaip9OQUCYsLaGwAKCRDOv4Eoaip9 OaK+AKCjBj68qX0xjZjcKFkVAgnNnHFwVACfSw/t8sE+T/dZA91Ta5URKC18PVI= =AOcP -----END PGP SIGNATURE----- dist.ini000664001750001750 7414260555033 13712 0ustar00taitai000000000000Role-Hooks-0.008;;class='Dist::Inkt::Profile::TOBYINK' ;;name='Role-Hooks' doap.ttl000664001750001750 2230014260555033 13772 0ustar00taitai000000000000Role-Hooks-0.008@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-deps:develop-recommendation [ doap-deps:on "Dist::Inkt 0.001"^^doap-deps:CpanId ]; doap-deps:runtime-requirement [ doap-deps:on "perl 5.008001"^^doap-deps:CpanId ], [ doap-deps:on "Class::Method::Modifiers"^^doap-deps:CpanId; ], [ doap-deps:on "List::Util 1.45"^^doap-deps:CpanId ]; doap-deps:test-recommendation [ doap-deps:on "Role::Tiny"^^doap-deps:CpanId ], [ doap-deps:on "Class::Tiny"^^doap-deps:CpanId ], [ doap-deps:on "Moo::Role"^^doap-deps:CpanId ], [ doap-deps:on "Moose::Role"^^doap-deps:CpanId ]; doap-deps:test-requirement [ doap-deps:on "Test::More 0.96"^^doap-deps:CpanId ], [ doap-deps:on "Test::Requires"^^doap-deps:CpanId ]; doap-deps:test-suggestion [ doap-deps:on "Role::Basic"^^doap-deps:CpanId ], [ doap-deps:on "Mouse::Role"^^doap-deps:CpanId ]; doap:bug-database ; doap:created "2020-02-18"^^xsd:date; doap:developer ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "Role-Hooks"; doap:programming-language "Perl"; doap:release , , , , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "role callbacks". a doap:Version; rdfs:label "Initial release"; dc:identifier "Role-Hooks-0.001"^^xsd:string; dc:issued "2020-02-18"^^xsd:date; doap-changeset:released-by ; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.002"^^xsd:string; dc:issued "2020-10-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Died applying a role to a non-Moo* class, with Moose loaded."; doap-changeset:fixes ; doap-changeset:thanks ; rdfs:comment "Fixed by using a variant of Safe::Isa to check metaclasses."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.003"^^xsd:string; dc:issued "2020-10-26"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Stop polluting Role::Tiny namespace."; doap-changeset:thanks ; rdfs:seeAlso ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.004"^^xsd:string; dc:issued "2022-06-07"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix, doap-changeset:Documentation; rdfs:label "Add missing `print` to print statements in examples."; doap-changeset:fixes ; doap-changeset:thanks ; ], [ a doap-changeset:Documentation, doap-changeset:Tests; rdfs:label "Test and document interaction with Package::Variant."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.005"^^xsd:string; dc:issued "2022-06-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Add after_inflate hook."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.006"^^xsd:string; dc:issued "2022-07-01"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Support for roles built using Mite."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.006"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.007"^^xsd:string; dc:issued "2022-07-04"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Eliminate 'used only once' warnings."; doap-changeset:thanks ; ], [ a doap-changeset:Tests; rdfs:label "Include a test that a known non-role returns false from is_role."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.007"^^xsd:string. a doap:Version; dc:identifier "Role-Hooks-0.008"^^xsd:string; dc:issued "2022-07-04"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix accidental dependency on Role::Tiny."; doap-changeset:thanks ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.008"^^xsd:string. a foaf:Person; foaf:name "Alexander Hartmaier"; foaf:nick "ABRAXXA"; foaf:page . a foaf:Person; foaf:name "Gianni Ceccarelli"; foaf:nick "DAKKAR"; foaf:page . a foaf:Person; foaf:name "Graham Knop"; foaf:nick "HAARG"; foaf:page . a foaf:Person; foaf:name "Tina Müller"; foaf:nick "TINITA"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . a doap-bugs:Issue; doap-bugs:id "133595"^^xsd:string; doap-bugs:page . a doap-bugs:Issue; doap-bugs:id "135361"^^xsd:string; doap-bugs:page . 01basic.t000664001750001750 67614260555033 14150 0ustar00taitai000000000000Role-Hooks-0.008/t=pod =encoding utf-8 =head1 PURPOSE Demonstration that Role::Hooks compiles. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2020 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_ok('Role::Hooks'); done_testing; 02roletiny.t000664001750001750 247714260555033 14756 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Role::Tiny'; }; { package Local::Dummy2; use Test::Requires 'Class::Tiny'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Role::Tiny; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Role::Tiny; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Class::Tiny; use Role::Tiny::With; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 03moorole.t000664001750001750 242514260555033 14557 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Moo'; }; { package Local::Dummy2; use Test::Requires 'Moo::Role'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Moo::Role; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Moo::Role; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Moo; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 04mooserole.t000664001750001750 243714260555033 15113 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Moose'; }; { package Local::Dummy2; use Test::Requires 'Moose::Role'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Moose::Role; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Moose::Role; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Moose; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 05mouserole.t000664001750001750 243714260555033 15122 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Mouse'; }; { package Local::Dummy2; use Test::Requires 'Mouse::Role'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Mouse::Role; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Mouse::Role; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Mouse; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 06rolebasic.t000664001750001750 250414260555033 15047 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Role::Basic'; }; { package Local::Dummy2; use Test::Requires 'Class::Tiny'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Role::Basic; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Role::Basic; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Class::Tiny; use Role::Basic 'with'; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 07mite.t000664001750001750 133614260555033 14045 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; use Test::Requires '5.010001'; use Test::Requires 'FindBin'; use Role::Hooks; use FindBin qw($Bin); use lib "@{[keys%{+{$Bin=>1}}]}/mite/lib"; # untaint :/ use Local::Class1; is_deeply(\%Local::xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%Local::xxx); done_testing; 10moorole_in_moose.t000664001750001750 243114260555033 16442 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Moose'; }; { package Local::Dummy2; use Test::Requires 'Moo::Role'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Moo::Role; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Moo::Role; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Moose; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 11mooserole_in_moo.t000664001750001750 243314260555033 16445 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Moo'; }; { package Local::Dummy2; use Test::Requires 'Moose::Role'; }; use Role::Hooks; my %xxx; { package Local::Role1; use Moose::Role; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Role2; use Moose::Role; with 'Local::Role1'; Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); } { package Local::Class1; use Moo; with 'Local::Role2'; } is_deeply(\%xxx, { 'Local::Role1' => [ [ 'before_apply', 'Local::Role1', 'Local::Role2' ], [ 'after_apply', 'Local::Role1', 'Local::Role2' ], [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ], 'Local::Role2' => [ [ 'before_apply', 'Local::Role2', 'Local::Class1' ], [ 'after_apply', 'Local::Role2', 'Local::Class1' ] ] }) or diag explain(\%xxx); done_testing; 20packagevariant.t000664001750001750 377514260555033 16073 0ustar00taitai000000000000Role-Hooks-0.008/t=pod =encoding utf-8 =head1 PURPOSE Demonstration that Role::Hooks works with L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2022 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; # This just skips the test if the necessary packages are unavailable. # { package Local::Dummy1; use Test::Requires 'Moo'; }; { package Local::Dummy2; use Test::Requires 'Moo::Role'; }; { package Local::Dummy2; use Test::Requires 'Package::Variant'; }; my @GOT; BEGIN { package Local::VariableRole; use Package::Variant importing => [ 'Moo::Role', 'Role::Hooks' ], subs => [ qw(has around before after with) ]; sub make_variant { # Note that the generated package name for the role is passed as the # first argument (after $self) to make_variant. # my ( $self, $role_name, %arguments ) = @_; my $name = $arguments{name}; has $name => ( is => 'ro' ); # That generated package name for the role must be passed to # before_apply. # 'Role::Hooks'->before_apply( $role_name, sub { my ( $role, $applied_to ) = @_; push @GOT, "About to add attribute $name to $applied_to"; } ); # The same for after_apply. # 'Role::Hooks'->after_apply( $role_name, sub { my ( $role, $applied_to ) = @_; push @GOT, "Applied attribute $name to $applied_to"; } ); } $INC{'Local/VariableRole.pm'} = __FILE__; }; BEGIN { package Local::MyClass; use Moo; use Local::VariableRole; with VariableRole( name => 'foo' ), VariableRole( name => 'bar' ); }; is_deeply( [ sort { $a cmp $b } @GOT ], [ sort { $a cmp $b } ( 'About to add attribute foo to Local::MyClass', 'About to add attribute bar to Local::MyClass', 'Applied attribute foo to Local::MyClass', 'Applied attribute bar to Local::MyClass', ) ], 'Expected result', ) or diag explain( \@GOT ); done_testing; 30inflate.t000664001750001750 165114260555033 14525 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; { package Local::Dummy1; use Test::Requires 'Moo'; }; my @got; { package Local::MyClass; use Moo; 'Role::Hooks'->after_inflate( __PACKAGE__, sub { push @got, "Classy!"; } ); } { package Local::MyRole1; use Moo::Role; use Role::Hooks; 'Role::Hooks'->after_inflate( __PACKAGE__, sub { push @got, @_; } ); } { package Local::MyRole2; use Moo::Role; with 'Local::MyRole1'; } is_deeply( [ sort @got ], [], 'Nothing so far', ); if ( eval 'package XYZ; use Moose; with "Local::MyRole2"; 1' ) { is_deeply( [ sort @got ], [ 'Local::MyRole1', 'Local::MyRole2' ], 'Both packages listed', ) or diag explain( \@got ); Local::MyClass->meta->name; is_deeply( [ sort @got ], [ 'Classy!', 'Local::MyRole1', 'Local::MyRole2' ], 'Three packages listed', ) or diag explain( \@got ); } else { note "Skipped inflation test as Moose wouldn't load"; } done_testing; 99nonrole.t000664001750001750 24514260555033 14554 0ustar00taitai000000000000Role-Hooks-0.008/tuse strict; use warnings; use Test::More; use Role::Hooks; BEGIN { package Foo; sub new { bless [], shift } }; ok ! Role::Hooks->is_role( 'Foo' ); done_testing; rt-133595.t000664001750001750 164014260555033 14132 0ustar00taitai000000000000Role-Hooks-0.008/t=pod =encoding utf-8 =head1 PURPOSE Calling C on undefined value in Role::Hooks 0.001. =head1 SEE ALSO L =head1 AUTHOR Gianni Ceccarelli Edakkar@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2020 by Gianni Ceccarelli. 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; { package Local::Dummy1; use Test::Requires 'Moose'; }; { package Local::Dummy2; use Test::Requires 'Role::Tiny'; }; use Role::Hooks; my @ARGS; { package MyRole; use Role::Tiny; Role::Hooks->before_apply( __PACKAGE__, sub { push @ARGS, [ @_ ] } ); } { package OtherRole; use Role::Tiny; } { package MyClass; use Role::Tiny::With; with 'OtherRole'; # <--- this throws } is_deeply( \@ARGS, [] ); done_testing; Hooks.pm000664001750001750 4072014260555033 15420 0ustar00taitai000000000000Role-Hooks-0.008/lib/Roleuse 5.008001; use strict; use warnings; package Role::Hooks; use Class::Method::Modifiers qw( install_modifier ); our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.008'; our %CALLBACKS_BEFORE_APPLY; our %CALLBACKS_AFTER_APPLY; our %CALLBACKS_AFTER_INFLATE; our %ARGS; BEGIN { *DEBUG = $ENV{'PERL_ROLE_HOOKS_DEBUG'} ? sub(){1} : sub(){0} }; # limited version of Safe::Isa my $_isa = sub { ref( $_[0] ) and $_[0]->isa( $_[1] ) }; sub _croak { my ($me, $msg, @args) = @_; require Carp; Carp::croak( @args ? sprintf($msg, @args) : $msg ); } sub _carp { my ($me, $msg, @args) = @_; require Carp; Carp::carp( @args ? sprintf($msg, @args) : $msg ); } sub _debug { my ($me, $msg, @args) = @_; require Carp; Carp::carp( @args ? sprintf($msg, @args) : $msg ) if DEBUG; } sub is_role { my $target = pop; if ($INC{'Role/Tiny.pm'} and 'Role::Tiny'->can('is_role') and 'Role::Tiny'->is_role($target)) { return 'Role::Tiny'; } # really old versions of Role::Tiny if ($INC{'Role/Tiny.pm'} and !'Role::Tiny'->can('is_role') and $Role::Tiny::INFO{$target}) { return 'Role::Tiny'; # uncoverable statement } if ($INC{'Moose/Meta/Role.pm'} and do { require Moose::Util; 1 } and Moose::Util::find_meta($target)->$_isa('Moose::Meta::Role')) { return 'Moose::Role'; } if ($INC{'Mouse/Meta/Role.pm'} and do { require Mouse::Util; 1 } and Mouse::Util::find_meta($target)->$_isa('Mouse::Meta::Role')) { return 'Mouse::Role'; } if ($INC{'Role/Basic.pm'} and eval { 'Role::Basic'->_load_role($target) }) { return 'Role::Basic'; } no strict 'refs'; no warnings 'once'; my $UM = ${"$target\::USES_MITE"}; if ( defined $UM and $UM eq 'Mite::Role' ) { return 'Mite::Role'; } return undef; } sub before_apply { my ($me, $target, @callbacks) = @_; return unless @callbacks; $me->is_role($target) or $me->_croak('%s is not a role', $target); $me->_install_patches($target); push @{ $CALLBACKS_BEFORE_APPLY{$target}||=[] }, @callbacks; return $me; } sub after_apply { my ($me, $target, @callbacks) = @_; return unless @callbacks; $me->is_role($target) or $me->_croak('%s is not a role', $target); $me->_install_patches($target); push @{ $CALLBACKS_AFTER_APPLY{$target}||=[] }, @callbacks; return $me; } sub after_inflate { no warnings 'uninitialized'; my ($me, $target, @callbacks) = @_; return unless @callbacks; $me->is_role($target) eq 'Role::Tiny' or $target->isa('Moo::Object') or $me->_croak('%s is not a Moo class or role', $target); $me->_install_patches($target); $me->_install_patches_inflation($target); push @{ $CALLBACKS_AFTER_INFLATE{$target}||=[] }, @callbacks; return $me; } { # Internals for monkey-patching role implementations. # my %patched; sub _install_patches { my ($me, $target) = @_; if ($INC{'Role/Tiny.pm'}) { $patched{'Role::Tiny'} ||= $me->_install_patches_roletiny; } if ($INC{'Moo/Role.pm'} or $INC{'Moo.pm'}) { $patched{'Moo::Role'} ||= $me->_install_patches_moorole; } if ($INC{'Moose/Role.pm'} or $INC{'Moose.pm'}) { $patched{'Moose::Role'} ||= $me->_install_patches_mooserole; } if ($INC{'Mouse/Role.pm'} or $INC{'Mouse.pm'}) { $patched{'Mouse::Role'} ||= $me->_install_patches_mouserole; } if ($INC{'Role/Basic.pm'}) { $patched{'Role::Basic'} ||= $me->_install_patches_rolebasic; } my $is_role = $me->is_role($target); if ( defined $is_role and $is_role eq 'Mite::Role' ) { $patched{'Mite::Role'}{$target} ||= $me->_install_patches_miterole($target); } } my %patched_inflation; sub _install_patches_inflation { my ($me, $target) = @_; if ($INC{'Moo/Role.pm'} or $INC{'Moo.pm'}) { $patched_inflation{'Moo::Role'} ||= $me->_install_patches_moorole_inflation; } } sub _install_patches_roletiny { my ($me) = @_; return 1 if $patched{'Role::Tiny'}; $me->_debug("Installing patches for Role::Tiny") if DEBUG; require Role::Tiny; install_modifier 'Role::Tiny', around => 'role_application_steps', sub { my $orig = shift; my @steps = $orig->(@_); return ( __PACKAGE__ . '::_run_role_tiny_before_callbacks', @steps, __PACKAGE__ . '::_run_role_tiny_after_callbacks', ); }; *_run_role_tiny_before_callbacks = sub { my (undef, $to, $role) = @_; $me->_debug("Calling role hooks for $role before application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } return; }; *_run_role_tiny_after_callbacks = sub { my (undef, $to, $role) = @_; $me->_debug("Calling role hooks for $role after application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } if (my $is_role = $me->is_role($to)) { $me->_debug("Copying role hooks for $role to $to") if DEBUG; $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }); $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] }); if ($is_role eq 'Role::Tiny' or $to->isa('Moo::Object')) { $me->after_inflate($to, @{ $CALLBACKS_AFTER_INFLATE{$role} || [] }); } } return; }; return 1; } sub _install_patches_moorole { my ($me) = @_; $patched{'Role::Tiny'} ||= $me->_install_patches_roletiny; return 1 if $patched{'Moo::Role'}; $me->_debug("Installing patches for Moo::Role") if DEBUG; require Moo::Role; require List::Util; # Mostly can just rely on Role::Tiny, but need # to move _run_callbacks_before_apply to the # front of the queue! # install_modifier 'Moo::Role', around => 'role_application_steps', sub { my $orig = shift; my @steps = $orig->(@_); return List::Util::uniqstr( __PACKAGE__ . '::_run_role_tiny_before_callbacks', @steps, ); }; return 1; } sub _install_patches_moorole_inflation { my ($me) = @_; return 1 if $patched_inflation{'Moo::Role'}; $me->_debug("Installing inflation patches for Moo::Role") if DEBUG; require Moo::HandleMoose; install_modifier 'Moo::HandleMoose', after => 'inject_real_metaclass_for', sub { my ( $name ) = @_; $me->_run_moo_inhale_callbacks( $name ); }; my %already; *_run_moo_inhale_callbacks = sub { my (undef, $name) = @_; $me->_debug("Calling role hooks for $name after inflation") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_INFLATE{$name} || [] }; for my $cb (@callbacks) { next if $already{"$name|$cb"}++; $cb->($name); } }; return 1; } sub _install_patches_mooserole { my ($me) = @_; return 1 if $patched{'Moose::Role'}; $me->_debug("Installing patches for Moose::Role") if DEBUG; require Moose::Meta::Role; install_modifier 'Moose::Meta::Role', around => 'apply', sub { my ($orig, $role_meta, $to_meta, %args) = @_; local *ARGS = \%args; my $role = $role_meta->name; my $to = $to_meta->name; do { $me->_debug("Calling role hooks for $role before application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; my $application = $role_meta->$orig($to_meta, %args); do { $me->_debug("Calling role hooks for $role after application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; if ($me->is_role($to)) { $me->_debug("Copying role hooks for $role to $to") if DEBUG; $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }); $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] }); } return $application; }; return 1; } sub _install_patches_mouserole { my ($me) = @_; return 1 if $patched{'Mouse::Role'}; $me->_debug("Installing patches for Mouse::Role") if DEBUG; require Mouse::Meta::Role; install_modifier 'Mouse::Meta::Role', around => 'apply', sub { my ($orig, $role_meta, $to_meta, %args) = @_; local *ARGS = \%args; my $role = $role_meta->name; my $to = $to_meta->name; do { $me->_debug("Calling role hooks for $role before application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; my $application = $role_meta->$orig($to_meta, %args); do { $me->_debug("Calling role hooks for $role after application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; if ($me->is_role($to)) { $me->_debug("Copying role hooks for $role to $to") if DEBUG; $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }); $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] }); } return $application; }; return 1; } sub _install_patches_rolebasic { my ($me) = @_; return 1 if $patched{'Role::Basic'}; $me->_debug("Installing patches for Role::Basic") if DEBUG; require Role::Basic; $me->_carp("Role::Hooks is only tested with Role::Basic 0.07 to 0.13") unless $Role::Basic::VERSION =~ /^0\.(?:0[7-9]|1[0-3])/; install_modifier 'Role::Basic', around => '_add_role_methods_to_target', sub { my ($orig, $rb, $role, $to, $modifiers) = @_; local *ARGS = $modifiers; do { $me->_debug("Calling role hooks for $role before application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; my $application = $rb->$orig($role, $to, $modifiers); do { $me->_debug("Calling role hooks for $role after application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } }; if ($me->is_role($to)) { $me->_debug("Copying role hooks for $role to $to") if DEBUG; $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }); $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] }); } return $application; }; return 1; } sub _install_patches_miterole { my ($me, $target) = @_; return 1 if $ENV{MITE_COMPILE}; install_modifier $target, around => '__FINALIZE_APPLICATION__', sub { my ($orig, $role, $to, $modifiers) = @_; local *ARGS = $modifiers || {}; my $indirect = ( $modifiers || {} )->{-indirect}; if ( not $indirect ) { $me->_debug("Calling role hooks for $role before application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } } $role->$orig($to, $modifiers); if ( not $indirect ) { $me->_debug("Calling role hooks for $role after application to $to") if DEBUG; my @callbacks = @{ $CALLBACKS_AFTER_APPLY{$role} || [] }; for my $cb (@callbacks) { $cb->($role, $to); } } my $to_type = $me->is_role($to); if (defined $to_type and $to_type eq 'Mite::Role') { $me->_debug("Copying role hooks for $role to $to") if DEBUG; $me->before_apply($to, @{ $CALLBACKS_BEFORE_APPLY{$role} || [] }); $me->after_apply($to, @{ $CALLBACKS_AFTER_APPLY{$role} || [] }); } }; 1; } } 1; __END__ =pod =encoding utf-8 =head1 NAME Role::Hooks - role callbacks =head1 SYNOPSIS package Local::Role { use Moo::Role; use Role::Hooks; Role::Hooks->after_apply(__PACKAGE__, sub { my ($role, $target) = @_; print "$role has been applied to $target.\n"; }); } package Local::Class { use Moo; with "Local::Role"; # prints above message } =head1 DESCRIPTION This module allows a role to run a callback when it is applied to a class or to another role. =head2 Compatibility It should work with L, L, L, L, L, and L. Not all class builders work well with all role builders (for example, a Moose class consuming a Mouse role). But when they do work together, Role::Hooks should be able to run the callbacks. (The only combination I've tested is Moo with Moose though.) Some other role implementations (such as L, L, and L) are just wrappers around one of the supported role builders, so should mostly work. With Role::Basic, the C hook is called a little earlier than would be ideal; after the role has been fully loaded and its methods have been copied into the target package, but before handling C, and before patching the C method in the target package. If you are using Role::Basic, consider switching to Role::Tiny. With Mite, the C hook is called fairly late; after the role is fully loaded and attributes and methods have been copied into the target package, after C has been patched, but before method modifiers from the role have been applied to the target package. Apart from Role::Tiny/Moo::Role, a hashref of additional arguments (things like "-excludes" and "-alias") can be passed when consuming a role. Although I discourage people from using these in general, if you need access to these arguments in the callback, you can check C<< %Role::Hooks::ARGS >>. Roles generated via L should work; see F for a demonstration. =head2 Methods =over =item C<< before_apply >> Role::Hooks->before_apply($rolename, $callback); Sets up a callback for a role that will be called before the role is applied to a target package. The callback will be passed two parameters: the role being applied and the target package. The role being applied may not be the same role as the role the callback was defined in! package Local::Role1 { use Moo::Role; use Role::Hooks; Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; print "$role has been applied to $target.\n"; }); } package Local::Role2 { use Moo::Role; with "Local::Role1"; } package Local::Class1 { use Moo::Role; with "Local::Role2"; } This will print: Local::Role1 has been applied to Local::Role2. Local::Role2 has been applied to Local::Class1. If you only care about direct applications of roles (i.e. the first one): Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; return if $role ne __PACKAGE__; print "$role has been applied to $target.\n"; }); If you only care about roles being applied to classes (i.e. the second one): Role::Hooks->before_apply(__PACKAGE__, sub { my ($role, $target) = @_; return if Role::Hooks->is_role($target); print "$role has been applied to $target.\n"; }); =item C<< after_apply >> Role::Hooks->after_apply($rolename, $callback); The same as C<< before_apply >>, but called later in the role application process. Note that when the callback is called, even though it's after the role has been applied to the target, it doesn't mean the target has finished being built. For example, there might be C statements after the C statement, and those will not have been evaluated yet. If you want to throw an error when someone applies your role to an inappropriate target, it is probably better to do that in C if you can. =item C<< after_inflate >> Role::Hooks->after_inflate($pkg_name, $callback); Even though this is part of Role::Hooks, it works on classes too. But it only works on classes and roles built using Moo. This runs your callback if your Moo class or role gets "inflated" to a Moose class or role. If you set up a callback for a role, then the callback will also get called if any packages that role was applied to get inflated. =item C<< is_role >> Will return true if the given package seems to be a role, false otherwise. (In fact, returns a string representing which role builder the role seems to be using -- "Role::Tiny", "Moose::Role", "Mouse::Role", "Role::Basic", or "Mite::Role"; roles built using Moo::Role are detected as "Role::Tiny".) =back =head1 ENVIRONMENT The environment variable C may be set to true to enable debugging messages. =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2020-2022 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. =head1 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. config000664001750001750 10714260555033 15670 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/.mite--- compiled_to: lib project: Local shim: Local::Mite source_from: lib Class1.pm000664001750001750 10114260555033 16742 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Localpackage Local::Class1; use Local::Mite; with 'Local::Role2'; 1; Class1.pm.mite.pm000664001750001750 473114260555033 20347 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Local{ ## skip Test::Tabs package Local::Class1; our $USES_MITE = q[Mite::Class]; use strict; use warnings; BEGIN { require Local::Role2; our %DOES = ( q[Local::Class1] => 1, q[Local::Role2] => 1, q[Local::Role1] => 1 ); } sub new { my $class = ref($_[0]) ? ref(shift) : shift; my $meta = ( $Mite::META{$class} ||= $class->__META__ ); my $self = bless {}, $class; my $args = $meta->{HAS_BUILDARGS} ? $class->BUILDARGS( @_ ) : { ( @_ == 1 ) ? %{$_[0]} : @_ }; my $no_build = delete $args->{__no_BUILD__}; # Initialize attributes # Enforce strict constructor my @unknown = grep not( do { package Local::Mite; defined($_) and do { ref(\$_) eq 'SCALAR' or ref(\(my $val = $_)) eq 'SCALAR' } } ), keys %{$args}; @unknown and require Carp and Carp::croak("Unexpected keys in constructor: " . join(q[, ], sort @unknown)); # Call BUILD methods unless ( $no_build ) { $_->($self, $args) for @{ $meta->{BUILD} || [] } }; return $self; } defined ${^GLOBAL_PHASE} or eval { require Devel::GlobalDestruction; 1 } or do { *Devel::GlobalDestruction::in_global_destruction = sub { undef; } }; sub DESTROY { my $self = shift; my $class = ref( $self ) || $self; my $meta = ( $Mite::META{$class} ||= $class->__META__ ); my $in_global_destruction = defined ${^GLOBAL_PHASE} ? ${^GLOBAL_PHASE} eq 'DESTRUCT' : Devel::GlobalDestruction::in_global_destruction(); for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) { my $e = do { local ( $?, $@ ); eval { $demolisher->( $self, $in_global_destruction ) }; $@; }; no warnings 'misc'; # avoid (in cleanup) warnings die $e if $e; # rethrow } return; } sub __META__ { no strict 'refs'; require mro; my $class = shift; $class = ref($class) || $class; my $linear_isa = mro::get_linear_isa( $class ); return { BUILD => [ map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () } map { "$_\::BUILD" } reverse @$linear_isa ], DEMOLISH => [ map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () } map { "$_\::DEMOLISH" } @$linear_isa ], HAS_BUILDARGS => $class->can('BUILDARGS'), }; } sub DOES { my ( $self, $role ) = @_; our %DOES; return $DOES{$role} if exists $DOES{$role}; return 1 if $role eq __PACKAGE__; return $self->SUPER::DOES( $role ); } sub does { shift->DOES( @_ ); } 1; }Mite.pm000664001750001750 1443714260555033 16573 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Local## skip Test::Tabs use 5.010001; use strict; use warnings; package Local::Mite; # NOTE: Since the intention is to ship this file with a project, this file # cannot have any non-core dependencies. use strict; use warnings; sub _is_compiling { return $ENV{MITE_COMPILE} ? 1 : 0; } sub _make_has { my ( $class, $caller, $file, $kind ) = @_; return sub { my $names = shift; $names = [$names] unless ref $names; my %args = @_; for my $name ( @$names ) { $name =~ s/^\+//; my $default = $args{default}; if ( ref $default eq 'CODE' ) { no strict 'refs'; ${$caller .'::__'.$name.'_DEFAULT__'} = $default; } my $builder = $args{builder}; if ( ref $builder eq 'CODE' ) { no strict 'refs'; *{"$caller\::_build_$name"} = $builder; } my $trigger = $args{trigger}; if ( ref $trigger eq 'CODE' ) { no strict 'refs'; *{"$caller\::_trigger_$name"} = $trigger; } } return; }; } sub import { my ( $class, $kind ) = @_; my ( $caller, $file ) = caller; # Turn on warnings and strict in the caller warnings->import; strict->import; $kind ||= 'class'; $kind = ( $kind =~ /role/i ) ? 'role' : 'class'; if( _is_compiling() ) { require Mite::Project; my $method = "inject_mite_$kind\_functions"; Mite::Project->default->$method( package => $caller, file => $file, ); } else { # Work around Test::Compile's tendency to 'use' modules. # Mite.pm won't stand for that. return if $ENV{TEST_COMPILE}; # Changes to this filename must be coordinated with Mite::Compiled my $mite_file = $file . ".mite.pm"; if( !-e $mite_file ) { require Carp; Carp::croak("Compiled Mite file ($mite_file) for $file is missing"); } { local @INC = ('.', @INC); require $mite_file; } my $method = "_inject_mite_$kind\_functions"; $class->$method( $caller, $file ); } } my $parse_mm_args = sub { my $coderef = pop; my $names = [ map { ref($_) ? @$_ : $_ } @_ ]; ( $names, $coderef ); }; { my $get_orig = sub { my ( $caller, $name ) = @_; \&{ "$caller\::$name" }; }; sub before { my ( $me, $caller ) = ( shift, shift ); my ( $names, $coderef ) = &$parse_mm_args; for my $name ( @$names ) { my $orig = $get_orig->( $caller, $name ); local $@; eval <<"BEFORE" or die $@; package $caller; no warnings 'redefine'; sub $name { \$coderef->( \@_ ); \$orig->( \@_ ); } 1; BEFORE } return; } sub after { my ( $me, $caller ) = ( shift, shift ); my ( $names, $coderef ) = &$parse_mm_args; for my $name ( @$names ) { my $orig = $get_orig->( $caller, $name ); local $@; eval <<"AFTER" or die $@; package $caller; no warnings 'redefine'; sub $name { my \@r; if ( wantarray ) { \@r = \$orig->( \@_ ); } elsif ( defined wantarray ) { \@r = scalar \$orig->( \@_ ); } else { \$orig->( \@_ ); 1; } \$coderef->( \@_ ); wantarray ? \@r : \$r[0]; } 1; AFTER } return; } sub around { my ( $me, $caller ) = ( shift, shift ); my ( $names, $coderef ) = &$parse_mm_args; for my $name ( @$names ) { my $orig = $get_orig->( $caller, $name ); local $@; eval <<"AROUND" or die $@; package $caller; no warnings 'redefine'; sub $name { \$coderef->( \$orig, \@_ ); } 1; AROUND } return; } } sub _inject_mite_class_functions { my ( $class, $caller, $file ) = ( shift, @_ ); no strict 'refs'; *{ $caller .'::has' } = $class->_make_has( $caller, $file, 'class' ); *{ $caller .'::with' } = sub { while ( @_ ) { my $role = shift; my $args = ref($_[0]) ? shift : undef; $role->__FINALIZE_APPLICATION__( $caller, $args ); } }; *{ $caller .'::extends'} = sub {}; for my $mm ( qw/ before after around / ) { *{"$caller\::$mm"} = sub { $class->$mm( $caller, @_ ); return; }; } } sub _inject_mite_role_functions { my ( $class, $caller, $file ) = ( shift, @_ ); no strict 'refs'; *{ $caller .'::has' } = $class->_make_has( $caller, $file, 'role' ); *{ $caller .'::with' } = sub { while ( @_ ) { my $role = shift; my $args = ref($_[0]) ? shift : undef; $role->__FINALIZE_APPLICATION__( $caller, $args ); } }; my $MM = \@{"$caller\::METHOD_MODIFIERS"}; for my $modifier ( qw/ before after around / ) { *{ $caller .'::'. $modifier } = sub { my ( $names, $coderef ) = &$parse_mm_args; push @$MM, [ $modifier, $names, $coderef ]; }; } } 1; __END__ =pod =head1 NAME Local::Mite - shim to load .mite.pm files =head1 DESCRIPTION This is a copy of L. =head1 AUTHOR Michael G Schwern Emschwern@cpan.orgE. Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2011-2014 by Michael G Schwern. This software is copyright (c) 2022 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. =head1 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. =cut Role1.pm000664001750001750 45214260555033 16607 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Localpackage Local::Role1; use Local::Mite -role; use Role::Hooks (); Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $Local::xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $Local::xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); 1; Role1.pm.mite.pm000664001750001750 225714260555033 20204 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Local{ ## skip Test::Tabs package Local::Role1; our $USES_MITE = q[Mite::Role]; use strict; use warnings; sub DOES { my ( $self, $role ) = @_; our %DOES; return $DOES{$role} if exists $DOES{$role}; return 1 if $role eq __PACKAGE__; return $self->SUPER::DOES( $role ); } sub does { shift->DOES( @_ ); } # Callback which classes consuming this role will call sub __FINALIZE_APPLICATION__ { my ( $me, $target, $args ) = @_; our ( %CONSUMERS, @METHOD_MODIFIERS ); # Ensure a given target only consumes this role once. if ( exists $CONSUMERS{$target} ) { return; } $CONSUMERS{$target} = 1; my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} }; if ( $type ne 'Mite::Class' ) { return; } my @roles = ( ); my %nextargs = %{ $args || {} }; ( $nextargs{-indirect} ||= 0 )++; for my $role ( @roles ) { $role->__FINALIZE_APPLICATION__( $target, { %nextargs } ); } my $shim = q[Local::Mite]; for my $modifier_rule ( @METHOD_MODIFIERS ) { my ( $modification, $names, $coderef ) = @$modifier_rule; $shim->$modification( $target, $names, $coderef ); } return; } 1; }Role2.pm000664001750001750 47714260555033 16617 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Localpackage Local::Role2; use Local::Mite -role; with 'Local::Role1'; use Role::Hooks (); Role::Hooks->before_apply(__PACKAGE__, sub { push @{ $Local::xxx{+__PACKAGE__}||=[] }, [before_apply => @_]; }); Role::Hooks->after_apply(__PACKAGE__, sub { push @{ $Local::xxx{+__PACKAGE__}||=[] }, [after_apply => @_]; }); 1; Role2.pm.mite.pm000664001750001750 244314260555033 20202 0ustar00taitai000000000000Role-Hooks-0.008/t/mite/lib/Local{ ## skip Test::Tabs package Local::Role2; our $USES_MITE = q[Mite::Role]; use strict; use warnings; BEGIN { require Local::Role1; our %DOES = ( q[Local::Role2] => 1, q[Local::Role1] => 1 ); } sub DOES { my ( $self, $role ) = @_; our %DOES; return $DOES{$role} if exists $DOES{$role}; return 1 if $role eq __PACKAGE__; return $self->SUPER::DOES( $role ); } sub does { shift->DOES( @_ ); } # Callback which classes consuming this role will call sub __FINALIZE_APPLICATION__ { my ( $me, $target, $args ) = @_; our ( %CONSUMERS, @METHOD_MODIFIERS ); # Ensure a given target only consumes this role once. if ( exists $CONSUMERS{$target} ) { return; } $CONSUMERS{$target} = 1; my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} }; if ( $type ne 'Mite::Class' ) { return; } my @roles = ( q[Local::Role1] ); my %nextargs = %{ $args || {} }; ( $nextargs{-indirect} ||= 0 )++; for my $role ( @roles ) { $role->__FINALIZE_APPLICATION__( $target, { %nextargs } ); } my $shim = q[Local::Mite]; for my $modifier_rule ( @METHOD_MODIFIERS ) { my ( $modification, $names, $coderef ) = @$modifier_rule; $shim->$modification( $target, $names, $coderef ); } return; } 1; }