MooseX-MarkAsMethods-0.15/0000775000175000017500000000000011761536207014413 5ustar cweylcweylMooseX-MarkAsMethods-0.15/README0000644000175000017500000001344611761536207015301 0ustar cweylcweylNAME MooseX::MarkAsMethods - Mark overload code symbols as methods VERSION This document describes version 0.15 of MooseX::MarkAsMethods - released May 30, 2012 as part of MooseX-MarkAsMethods. SYNOPSIS package Foo; use Moose; # mark overloads as methods and wipe other non-methods use MooseX::MarkAsMethods autoclean => 1; # define overloads, etc as normal use overload '""' => sub { shift->stringify }; package Baz; use Moose::Role; use MooseX::MarkAsMethods autoclean => 1; # overloads defined in a role will "just work" when the role is # composed into a class; they MUST use the anon-sub style invocation use overload '""' => sub { shift->stringify }; # additional methods generated outside Class::MOP/Moose can be marked, too use constant foo => 'bar'; __PACKAGE__->meta->mark_as_method('foo'); package Bar; use Moose; # order is important! use namespace::autoclean; use MooseX::MarkAsMethods; # ... DESCRIPTION MooseX::MarkAsMethods allows one to easily mark certain functions as Moose methods. This will allow other packages such as namespace::autoclean to operate without blowing away your overloads. After using MooseX::MarkAsMethods your overloads will be recognized by Class::MOP as being methods, and class extension as well as composition from roles with overloads will "just work". By default we check for overloads, and mark those functions as methods. If "autoclean => 1" is passed to import on using this module, we will invoke namespace::autoclean to clear out non-methods. TRAITS APPLIED Using this package causes a trait to be applied to your metaclass (for both roles and classes), that provides a mark_as_method() method. You can use this to mark newly generated methods at runtime (e.g. during class composition) that some other package has created for you. mark_as_method() is invoked with one or more names to mark as a method. We die on any error (e.g. name not in symbol table, already a method, etc). e.g. __PACKAGE__->meta->mark_as_method('newly_generated'); e.g. say you have some sugar from another package that creates accessors of some sort; you could mark them as methods via a method modifier: # called as __PACKAGE__->foo_generator('name', ...) after 'foo_generator' => sub { shift->meta->mark_as_method(shift); }; IMPLICATIONS FOR ROLES Using MooseX::MarkAsMethods in a role will cause Moose to track and treat your overloads like any other method defined in the role, and things will "just work". That's it. Except... note that due to the way overloads, roles, and Moose work, you'll need to use the coderef or anonymous subroutine approach to overload declaration, or things will not work as you expect. Remember, we're talking about _methods_ here, so we need to make it easy for overload to find the right method. The easiest (and supported) way to do this is to create an anonymous sub to wrap the overload method. That is, this will work: # note method resolution, things will "just work" use overload '""' => sub { shift->stringify }; ...and this will not: use overload '""' => 'stringify'; ...and will result in an error message like: # wah-wah Can't resolve method "???" overloading """" in package "overload" CAVEATS Roles See the "IMPLICATIONS FOR ROLES" section, above. meta->mark_as_method() You almost certainly don't need or want to do this. CMOP/Moose are fairly good about determining what is and what isn't a method, but not perfect. Before using this method, you should pause and think about why you need to. namespace::autoclean As currently implemented, we run our "method maker" at the end of the calling package's compile scope (B::Hooks::EndOfScope). As namespace::autoclean does the same thing, it's important that if namespace::autoclean is used that it be used BEFORE MooseX::MarkAsMethods, so that its end_of_scope block is run after ours. e.g. # yes! use namespace::autoclean; use MooseX::MarkAsMethods; # no -- overloads will be removed use MooseX::MarkAsMethods; use namespace::autoclean; The easiest way to invoke this module and clean out non-methods without having to worry about ordering is: use MooseX::MarkAsMethods autoclean => 1; SEE ALSO Please see those modules/websites for more information related to this module. * overload, B::Hooks::EndOfScope, namespace::autoclean, Class::MOP, * Moose. * MooseX::Role::WithOverloading does allow for overload application from * roles, but it does this by copying the overload symbols from the (not * namespace::autoclean'ed role) the symbols handing overloads during class * composition; we work by marking the overloads as methods and letting * CMOP/Moose handle them. SOURCE The development version is on github at and may be cloned from BUGS Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/moosex-markasmethods/issues When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. AUTHOR Chris Weyl COPYRIGHT AND LICENSE This software is Copyright (c) 2011 by Chris Weyl. This is free software, licensed under: The GNU Lesser General Public License, Version 2.1, February 1999 MooseX-MarkAsMethods-0.15/Changes0000644000175000017500000000403711761536207015710 0ustar cweylcweylChanges for MooseX-MarkAsMethods 0.15 2012-05-30 17:34:11 America/Los_Angeles * Document that overload declarations must use the anon sub style for methods to resolve correctly. * No code/functionality changes. 0.14 2011-11-03 21:08:52 America/Los_Angeles * honor the "into => 'X'" flag Sub::Exporter recognizes 0.13 2011-09-17 10:08:31 America/Los_Angeles * drop Perl6::Junction dependency; we don't use it (anymore?) 0.12 2011-09-16 11:10:21 America/Los_Angeles * restore Moose minimum version as 0.94 0.11 2011-03-31 15:07:38 America/Los_Angeles * Correct POD error * Switch to Dist::Zilla 0.10 - Mon Jun 14 2010 * Add author_requires for modules needed by xt/ bits. * MooseX/MarkAsMethods.pm was being a touch misleading, when asking for 0.90 of Moose. This fell out of sync with the requirements in Makefile.PL, and as such has been removed. 0.09 - Fri Jun 11 2010 * push Moose required version (rt#58309) 0.08 - Tue May 25 2010 * Remove "inc" from MANIFEST.SKIP... Not entirely sure how that snuck in there. 0.07 - Sat May 22 2010 * Use wrap_method_body() rather than using our own method metaclass subclass, and drop said subclass * Apply a trait to the class/role metaclass that provides a mark_as_method() method, and use that do do our method marking * Initial test-cases for after-the-fact method marking * Documentation updates w.r.t. the above 0.06 - Tue May 11 2010 * Added a couple additional test cases * Cleaned up our dependencies (*sigh*) 0.05 - Mon Dec 14 20:15:32 2009 -0800 Chris Weyl (2): make Perl6::Junction required for testing Updating $VERSION to 0.05 0.04 - Fri Dec 4 17:04:23 2009 -0800 Chris Weyl (4): use namespace::clean->import() abstract out o/l testing into check_overloads() unmark author boilerplate tests as TODO Updating $VERSION to 0.04 0.03 - Wed Nov 25 22:15:47 2009 -0800 Chris Weyl (2): .pm updates (autoclean) Rework and enlarge test suite. MooseX-MarkAsMethods-0.15/INSTALL0000644000175000017500000000176211761536207015450 0ustar cweylcweyl This is the Perl distribution MooseX-MarkAsMethods. Installing MooseX-MarkAsMethods is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm MooseX::MarkAsMethods 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 MooseX::MarkAsMethods ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan MooseX::MarkAsMethods ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % 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 ## Documentation MooseX-MarkAsMethods documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc MooseX::MarkAsMethods MooseX-MarkAsMethods-0.15/dist.ini0000644000175000017500000000046011761536207016055 0ustar cweylcweylname = MooseX-MarkAsMethods author = Chris Weyl license = LGPL_2_1 copyright_holder = Chris Weyl copyright_year = 2011 [@Filter] -bundle = @RSRCHBOY -remove = Test::Portability -remove = Test::UseAllModules autoprereqs_skip = ^(funcs|Test(Class|Role).*)$ [Test::Synopsis] MooseX-MarkAsMethods-0.15/MANIFEST0000644000175000017500000000117711761536207015550 0ustar cweylcweylChanges INSTALL MANIFEST META.json META.yml Makefile.PL README dist.ini lib/MooseX/MarkAsMethods.pm t/00-compile.t t/00-load.t t/000-report-versions-tiny.t t/100_class.t t/101_class_less_simple.t t/102_class_no_autoclean.t t/103_class_inheritance.t t/104_via_method_name.t t/105_via_method_name_with_fallback.t t/200_role_overload.t t/201_role_overload_using_class.t t/300_generated_methods.t t/400_import_via_into.t t/author-pod-spell.t t/funcs.pm t/release-consistent-version.t t/release-eol.t t/release-has-version.t t/release-no-smart-comments.t t/release-no-tabs.t t/release-pod-coverage.t t/release-pod-syntax.t t/release-synopsis.t MooseX-MarkAsMethods-0.15/META.yml0000644000175000017500000001557411761536207015676 0ustar cweylcweyl--- abstract: 'Mark overload code symbols as methods' author: - 'Chris Weyl ' build_requires: File::Find: 0 File::Temp: 0 Test::Moose: 0 Test::More: 0.92 overload: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300016, CPAN::Meta::Converter version 2.120921' license: lgpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-MarkAsMethods requires: B::Hooks::EndOfScope: 0 Moose: 0.94 Moose::Exporter: 0 Moose::Role: 0 Moose::Util::MetaRole: 0 namespace::autoclean: 0.12 perl: 5.006 strict: 0 warnings: 0 resources: bugtracker: https://github.com/RsrchBoy/moosex-markasmethods/issues homepage: http://metacpan.org/release/MooseX-MarkAsMethods/ repository: git://github.com/RsrchBoy/moosex-markasmethods.git version: 0.15 x_Dist_Zilla: plugins: - class: Dist::Zilla::Plugin::NextRelease name: '@Filter/NextRelease' version: 4.300016 - class: Dist::Zilla::Plugin::Git::Check name: '@Filter/@Git/Check' version: 1.121010 - class: Dist::Zilla::Plugin::Git::Commit name: '@Filter/@Git/Commit' version: 1.121010 - class: Dist::Zilla::Plugin::Git::Tag name: '@Filter/@Git/Tag' version: 1.121010 - class: Dist::Zilla::Plugin::Git::Push name: '@Filter/@Git/Push' version: 1.121010 - class: Dist::Zilla::Plugin::Git::NextVersion name: '@Filter/Git::NextVersion' version: 1.121010 - class: Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch name: '@Filter/@Git::CheckFor/Git::CheckFor::CorrectBranch' version: 0.004 - class: Dist::Zilla::Plugin::Git::CheckFor::Fixups name: '@Filter/@Git::CheckFor/Git::CheckFor::Fixups' version: 0.004 - class: Dist::Zilla::Plugin::GatherDir name: '@Filter/GatherDir' version: 4.300016 - class: Dist::Zilla::Plugin::PruneCruft name: '@Filter/PruneCruft' version: 4.300016 - class: Dist::Zilla::Plugin::License name: '@Filter/License' version: 4.300016 - class: Dist::Zilla::Plugin::ExecDir name: '@Filter/ExecDir' version: 4.300016 - class: Dist::Zilla::Plugin::ShareDir name: '@Filter/ShareDir' version: 4.300016 - class: Dist::Zilla::Plugin::MakeMaker name: '@Filter/MakeMaker' version: 4.300016 - class: Dist::Zilla::Plugin::InstallGuide name: '@Filter/InstallGuide' version: 1.200000 - class: Dist::Zilla::Plugin::Manifest name: '@Filter/Manifest' version: 4.300016 - class: Dist::Zilla::Plugin::SurgicalPkgVersion name: '@Filter/SurgicalPkgVersion' version: 0.0019 - class: Dist::Zilla::Plugin::ReadmeFromPod name: '@Filter/ReadmeFromPod' version: 0.16 - class: Dist::Zilla::Plugin::AutoPrereqs name: '@Filter/AutoPrereqs' version: 4.300016 - class: Dist::Zilla::Plugin::Prepender name: '@Filter/Prepender' version: 1.112280 - class: Dist::Zilla::Plugin::Test::PodSpelling name: '@Filter/Test::PodSpelling' version: 2.002004 - class: Dist::Zilla::Plugin::ConsistentVersionTest name: '@Filter/ConsistentVersionTest' version: 0.02 - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Filter/PodCoverageTests' version: 4.300016 - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Filter/PodSyntaxTests' version: 4.300016 - class: Dist::Zilla::Plugin::NoTabsTests name: '@Filter/NoTabsTests' version: 0.01 - class: Dist::Zilla::Plugin::EOLTests name: '@Filter/EOLTests' version: 0.02 - class: Dist::Zilla::Plugin::HasVersionTests name: '@Filter/HasVersionTests' version: 1.101420 - class: Dist::Zilla::Plugin::Test::Compile name: '@Filter/Test::Compile' version: 1.112820 - class: Dist::Zilla::Plugin::ExtraTests name: '@Filter/ExtraTests' version: 4.300016 - class: Dist::Zilla::Plugin::NoSmartCommentsTests name: '@Filter/NoSmartCommentsTests' version: 0.006 - class: Dist::Zilla::Plugin::MinimumPerl name: '@Filter/MinimumPerl' version: 1.003 - class: Dist::Zilla::Plugin::ReportVersions::Tiny name: '@Filter/ReportVersions::Tiny' version: 1.03 - class: Dist::Zilla::Plugin::MetaConfig name: '@Filter/MetaConfig' version: 4.300016 - class: Dist::Zilla::Plugin::MetaJSON name: '@Filter/MetaJSON' version: 4.300016 - class: Dist::Zilla::Plugin::MetaYAML name: '@Filter/MetaYAML' version: 4.300016 - class: Dist::Zilla::Plugin::TestRelease name: '@Filter/TestRelease' version: 4.300016 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Filter/ConfirmRelease' version: 4.300016 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Filter/UploadToCPAN' version: 4.300016 - class: Dist::Zilla::Plugin::GitHub::Meta name: '@Filter/GitHub::Meta' version: 0.19 - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@Filter/CheckPrereqsIndexed' version: 0.007 - class: Dist::Zilla::Plugin::GitHub::Update name: '@Filter/GitHub::Update' version: 0.19 - class: Dist::Zilla::Plugin::ArchiveRelease name: '@Filter/ArchiveRelease' version: 4.00 - class: Dist::Zilla::Plugin::PodWeaver name: '@Filter/PodWeaver' version: 3.101641 - class: Dist::Zilla::Plugin::PruneFiles name: '@Filter/PruneFiles' version: 4.300016 - class: Dist::Zilla::Plugin::CopyFilesFromBuild name: '@Filter/CopyFilesFromBuild' version: 0.103510 - class: Dist::Zilla::Plugin::ReadmeAnyFromPod name: '@Filter/ReadmePodInRoot' version: 0.120120 - class: Dist::Zilla::Plugin::InstallRelease name: '@Filter/InstallRelease' version: 0.008 - class: Dist::Zilla::Plugin::Test::Synopsis name: Test::Synopsis version: 2.0.1 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300016 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300016 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300016 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300016 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300016 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300016 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300016 MooseX-MarkAsMethods-0.15/META.json0000644000175000017500000002451311761536207016037 0ustar cweylcweyl{ "abstract" : "Mark overload code symbols as methods", "author" : [ "Chris Weyl " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300016, CPAN::Meta::Converter version 2.120921", "license" : [ "lgpl_2_1" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-MarkAsMethods", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "runtime" : { "requires" : { "B::Hooks::EndOfScope" : "0", "Moose" : "0.94", "Moose::Exporter" : "0", "Moose::Role" : "0", "Moose::Util::MetaRole" : "0", "namespace::autoclean" : "0.12", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Find" : "0", "File::Temp" : "0", "Test::Moose" : "0", "Test::More" : "0.92", "overload" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/RsrchBoy/moosex-markasmethods/issues" }, "homepage" : "http://metacpan.org/release/MooseX-MarkAsMethods/", "repository" : { "type" : "git", "url" : "git://github.com/RsrchBoy/moosex-markasmethods.git", "web" : "https://github.com/RsrchBoy/moosex-markasmethods" } }, "version" : "0.15", "x_Dist_Zilla" : { "plugins" : [ { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@Filter/NextRelease", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@Filter/@Git/Check", "version" : "1.121010" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "@Filter/@Git/Commit", "version" : "1.121010" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "@Filter/@Git/Tag", "version" : "1.121010" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "@Filter/@Git/Push", "version" : "1.121010" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "@Filter/Git::NextVersion", "version" : "1.121010" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch", "name" : "@Filter/@Git::CheckFor/Git::CheckFor::CorrectBranch", "version" : "0.004" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::Fixups", "name" : "@Filter/@Git::CheckFor/Git::CheckFor::Fixups", "version" : "0.004" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "name" : "@Filter/GatherDir", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Filter/PruneCruft", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Filter/License", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Filter/ExecDir", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Filter/ShareDir", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "name" : "@Filter/MakeMaker", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@Filter/InstallGuide", "version" : "1.200000" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Filter/Manifest", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::SurgicalPkgVersion", "name" : "@Filter/SurgicalPkgVersion", "version" : "0.0019" }, { "class" : "Dist::Zilla::Plugin::ReadmeFromPod", "name" : "@Filter/ReadmeFromPod", "version" : "0.16" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@Filter/AutoPrereqs", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::Prepender", "name" : "@Filter/Prepender", "version" : "1.112280" }, { "class" : "Dist::Zilla::Plugin::Test::PodSpelling", "name" : "@Filter/Test::PodSpelling", "version" : "2.002004" }, { "class" : "Dist::Zilla::Plugin::ConsistentVersionTest", "name" : "@Filter/ConsistentVersionTest", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Filter/PodCoverageTests", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Filter/PodSyntaxTests", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::NoTabsTests", "name" : "@Filter/NoTabsTests", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::EOLTests", "name" : "@Filter/EOLTests", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::HasVersionTests", "name" : "@Filter/HasVersionTests", "version" : "1.101420" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "name" : "@Filter/Test::Compile", "version" : "1.112820" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Filter/ExtraTests", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::NoSmartCommentsTests", "name" : "@Filter/NoSmartCommentsTests", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::MinimumPerl", "name" : "@Filter/MinimumPerl", "version" : "1.003" }, { "class" : "Dist::Zilla::Plugin::ReportVersions::Tiny", "name" : "@Filter/ReportVersions::Tiny", "version" : "1.03" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Filter/MetaConfig", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Filter/MetaJSON", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Filter/MetaYAML", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Filter/TestRelease", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Filter/ConfirmRelease", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Filter/UploadToCPAN", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::GitHub::Meta", "name" : "@Filter/GitHub::Meta", "version" : "0.19" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@Filter/CheckPrereqsIndexed", "version" : "0.007" }, { "class" : "Dist::Zilla::Plugin::GitHub::Update", "name" : "@Filter/GitHub::Update", "version" : "0.19" }, { "class" : "Dist::Zilla::Plugin::ArchiveRelease", "name" : "@Filter/ArchiveRelease", "version" : "4.00" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "name" : "@Filter/PodWeaver", "version" : "3.101641" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@Filter/PruneFiles", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromBuild", "name" : "@Filter/CopyFilesFromBuild", "version" : "0.103510" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "name" : "@Filter/ReadmePodInRoot", "version" : "0.120120" }, { "class" : "Dist::Zilla::Plugin::InstallRelease", "name" : "@Filter/InstallRelease", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::Test::Synopsis", "name" : "Test::Synopsis", "version" : "2.0.1" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300016" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300016" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300016" } } } MooseX-MarkAsMethods-0.15/t/0000775000175000017500000000000011761536207014656 5ustar cweylcweylMooseX-MarkAsMethods-0.15/t/funcs.pm0000644000175000017500000000521511761536207016333 0ustar cweylcweyl# # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # my @sugar = qw{ has around augment inner before after blessed confess }; sub check_sugar_removed_ok { my $t = shift @_; # check some (not all) Moose sugar to make sure it has been cleared #my @sugar = qw{ has around augment inner before after blessed confess }; ok !$t->can($_) => "$t cannot $_" for @sugar; return; } sub check_sugar_ok { my $t = shift @_; # check some (not all) Moose sugar to make sure it has been cleared #my @sugar = qw{ has around augment inner before after blessed confess }; ok $t->can($_) => "$t can $_" for @sugar; return; } sub make_and_check { #my $class = shift @_; my ($class, $roles, $atts) = @_; my $t = $class->new; isa_ok $t, $class; # do our class checks: meta, roles, attributes meta_ok $class; does_ok $class => $_ for @$roles; has_attribute_ok $class => $_ for @$atts; return $t; } sub check_overloads { my ($t, %overloads) = @_; die "We expect an instance of $t, not a classname" unless ref $t; my $class = ref $t; ok overload::Overloaded($class), "$class is subject to some overloads"; for my $op (keys %overloads) { # check that Moose knows about it, overload knows about it, and that # it works the way we expect it to if ($t->meta->has_method("($op")) { # we have the method and are its originator pass "$class still has o/l method ($op"; } else { # we have the method via inheriting, etc ok $t->meta->find_method_by_name("($op"), "$class inherits o/l method ($op"; } ok overload::Method($t, $op), "overload claims $class has $op overloaded"; is "$t", $overloads{$op}, "$class o/l returned the expected value"; } return; } sub check_methods { _check_methods(\&pass, \&fail, @_) } sub check_no_methods { _check_methods(\&fail, \&pass, @_) } sub _check_methods { my ($has, $not_has, $t, @methods) = @_; my $class = ref $t; for my $method (@methods) { # see if we have it directly... do { $has->("$class has method $method"); next } if $t->meta->has_method($method); # ... or via inheritance do { $has->("$class inherits method $method"); next } if $t->meta->find_method_by_name($method); # if we're here, it's a fail $not_has->("$class neither has nor inherits method $method"); } return; } 1; MooseX-MarkAsMethods-0.15/t/00-load.t0000644000175000017500000000062411761536207016177 0ustar cweylcweyl#!/usr/bin/env perl # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Test::More tests => 1; BEGIN { use_ok( 'MooseX::MarkAsMethods' ); } diag( "Testing MooseX::MarkAsMethods $MooseX::MarkAsMethods::VERSION, Perl $], $^X" ); MooseX-MarkAsMethods-0.15/t/100_class.t0000644000175000017500000000103111761536207016521 0ustar cweylcweyl use strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw'); sub stringify { 'from class' } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'from class'); done_testing; MooseX-MarkAsMethods-0.15/t/00-compile.t0000644000175000017500000000345711761536207016717 0ustar cweylcweyl#!perl # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use strict; use warnings; use Test::More; use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; # nothing to skip push @modules, $found; }, 'lib', ); sub _find_scripts { my $dir = shift @_; my @found_scripts = (); find( sub { return unless -f; my $found = $File::Find::name; # nothing to skip open my $FH, '<', $_ or do { note( "Unable to open $found in ( $! ), skipping" ); return; }; my $shebang = <$FH>; return unless $shebang =~ /^#!.*?\bperl\b\s*$/; push @found_scripts, $found; }, $dir, ); return @found_scripts; } my @scripts; do { push @scripts, _find_scripts($_) if -d $_ } for qw{ bin script scripts }; my $plan = scalar(@modules) + scalar(@scripts); $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); { # fake home for cpan-testers # no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 ); like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script 1.05; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file ( @scripts ) { my $script = $file; $script =~ s!.*/!!; script_compiles( $file, "$script script compiles" ); } } } MooseX-MarkAsMethods-0.15/t/release-eol.t0000644000175000017500000000047611761536207017245 0ustar cweylcweyl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::EOL'; plan skip_all => 'Test::EOL required' if $@; all_perl_files_ok({ trailing_whitespace => 1 }); MooseX-MarkAsMethods-0.15/t/release-no-tabs.t0000644000175000017500000000045011761536207020021 0ustar cweylcweyl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::NoTabs'; plan skip_all => 'Test::NoTabs required' if $@; all_perl_files_ok(); MooseX-MarkAsMethods-0.15/t/author-pod-spell.t0000644000175000017500000000104111761536207020234 0ustar cweylcweyl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.002004 eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $@; add_stopwords(); all_pod_files_spelling_ok('bin', 'lib'); __DATA__ AFAICT ABEND RSRCHBOY RSRCHBOY's ini metaclass metaclasses parameterized parameterization subclasses Chris Weyl lib MooseX MarkAsMethods MooseX-MarkAsMethods-0.15/t/release-synopsis.t0000644000175000017500000000101511761536207020343 0ustar cweylcweyl#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Test::More; eval "use Test::Synopsis"; plan skip_all => "Test::Synopsis required for testing synopses" if $@; all_synopsis_ok('lib'); MooseX-MarkAsMethods-0.15/t/200_role_overload.t0000644000175000017500000000144411761536207020261 0ustar cweylcweyluse strict; use warnings; { package TestRole; use Moose::Role; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; sub stringify { 'from role' } has role_att => (isa => 'Str', is => 'rw'); } { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; with 'TestRole'; #sub stringify { 'gotcha!' } has class_att => (isa => 'Str', is => 'rw'); } use Test::More 0.92; #tests => XX; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); check_sugar_removed_ok('TestRole'); my $t = make_and_check( 'TestClass', [ 'TestRole' ], [ qw{ role_att class_att } ], ); check_overloads($t, '""' => 'from role'); done_testing; MooseX-MarkAsMethods-0.15/t/release-pod-syntax.t0000644000175000017500000000100211761536207020556 0ustar cweylcweyl#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); MooseX-MarkAsMethods-0.15/t/104_via_method_name.t0000644000175000017500000000113511761536207020544 0ustar cweylcweyluse strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => 'stringify'; has class_att => (isa => 'Str', is => 'rw', lazy_build => 1); sub _build_class_att { 'class_att value' } sub stringify { 'val: ' . shift->class_att } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'val: class_att value'); done_testing; __END__ MooseX-MarkAsMethods-0.15/t/400_import_via_into.t0000644000175000017500000000215111761536207020625 0ustar cweylcweyl use strict; use warnings; use Moose ( ); use MooseX::MarkAsMethods ( ); use Test::More (); BEGIN { { package TestClass::Funky; use Moose::Exporter; my ($import, $unimport, $init_meta) = Moose::Exporter->build_import_methods( install => [ qw{ unimport init_meta } ], ); sub import { my $target = scalar caller; MooseX::MarkAsMethods->import({ into => $target }, autoclean => 1); goto &$import; } } $INC{'TestClass/Funky.pm'} = 1; } { package TestClass; use Moose; use TestClass::Funky; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw'); sub stringify { 'from class' } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; does_ok(TestClass->meta, 'MooseX::MarkAsMethods::MetaRole::MethodMarker'); check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'from class'); done_testing; MooseX-MarkAsMethods-0.15/t/release-has-version.t0000644000175000017500000000102511761536207020713 0ustar cweylcweyl#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Test::More; eval "use Test::HasVersion"; plan skip_all => "Test::HasVersion required for testing version numbers" if $@; all_pm_version_ok(); MooseX-MarkAsMethods-0.15/t/release-pod-coverage.t0000644000175000017500000000131711761536207021034 0ustar cweylcweyl#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); MooseX-MarkAsMethods-0.15/t/101_class_less_simple.t0000644000175000017500000000117211761536207021127 0ustar cweylcweyl use strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw', lazy_build => 1); sub _build_class_att { 'class_att value' } sub stringify { 'val: ' . shift->class_att } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'val: class_att value'); done_testing; __END__ MooseX-MarkAsMethods-0.15/t/103_class_inheritance.t0000644000175000017500000000170211761536207021102 0ustar cweylcweyluse strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw'); sub stringify { 'from class' } } { package TestClass::Baby; use Moose; use MooseX::MarkAsMethods autoclean => 1; extends 'TestClass'; #use overload q{""} => sub { shift->stringify }, fallback => 1; has baby_class_att => (isa => 'Str', is => 'rw'); #sub stringify { 'from class' } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); check_sugar_removed_ok('TestClass::Baby'); my $T = make_and_check('TestClass'); my $t = make_and_check( 'TestClass::Baby', undef, [ qw{ class_att baby_class_att } ], ); check_overloads($T, '""', 'from class'); check_overloads($t, '""', 'from class'); done_testing; MooseX-MarkAsMethods-0.15/t/300_generated_methods.t0000644000175000017500000000214011761536207021101 0ustar cweylcweyluse strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw'); sub stringify { 'from class' } { # CMOP/Moose will successfully find this as a method no strict 'refs'; *{"gen3"} = sub { 'gen3 called' }; } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'from class'); check_methods($t, 'gen1'); check_methods($t, 'gen3'); # this should also be found as a method, no tinkering necessary sub TestClass::gen1 { 'gen1 called' } { # CMOP/Moose will not find this as a method. check_no_methods($t, 'gen2'); no strict 'refs'; *{"TestClass" . '::' . "gen2"} = sub { 'gen2 called' }; check_no_methods($t, 'gen2'); TestClass->meta->mark_as_method('gen2'); check_methods($t, 'gen2'); } done_testing; MooseX-MarkAsMethods-0.15/t/102_class_no_autoclean.t0000644000175000017500000000103511761536207021256 0ustar cweylcweyluse strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods; # autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; has class_att => (isa => 'Str', is => 'rw'); sub stringify { 'from class' } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ qw{ class_att } ], ); check_overloads($t, '""', 'from class'); done_testing; __END__ MooseX-MarkAsMethods-0.15/t/000-report-versions-tiny.t0000644000175000017500000000470311761536207021504 0ustar cweylcweyluse strict; use warnings; use Test::More 0.88; # This is a relatively nice way to avoid Test::NoWarnings breaking our # expectations by adding extra tests, without using no_plan. It also helps # avoid any other test module that feels introducing random tests, or even # test plans, is a nice idea. our $success = 0; END { $success && done_testing; } my $v = "\n"; eval { # no excuses! # report our Perl details my $want = '5.006'; my $pv = ($^V || $]); $v .= "perl: $pv (wanted $want) on $^O from $^X\n\n"; }; defined($@) and diag("$@"); # Now, our module version dependencies: sub pmver { my ($module, $wanted) = @_; $wanted = " (want $wanted)"; my $pmver; eval "require $module;"; if ($@) { if ($@ =~ m/Can't locate .* in \@INC/) { $pmver = 'module not found.'; } else { diag("${module}: $@"); $pmver = 'died during require.'; } } else { my $version; eval { $version = $module->VERSION; }; if ($@) { diag("${module}: $@"); $pmver = 'died during VERSION check.'; } elsif (defined $version) { $pmver = "$version"; } else { $pmver = ''; } } # So, we should be good, right? return sprintf('%-45s => %-10s%-15s%s', $module, $pmver, $wanted, "\n"); } eval { $v .= pmver('B::Hooks::EndOfScope','any version') }; eval { $v .= pmver('ExtUtils::MakeMaker','6.30') }; eval { $v .= pmver('File::Find','any version') }; eval { $v .= pmver('File::Temp','any version') }; eval { $v .= pmver('Moose','0.94') }; eval { $v .= pmver('Moose::Exporter','any version') }; eval { $v .= pmver('Moose::Role','any version') }; eval { $v .= pmver('Moose::Util::MetaRole','any version') }; eval { $v .= pmver('Test::Moose','any version') }; eval { $v .= pmver('Test::More','0.92') }; eval { $v .= pmver('namespace::autoclean','0.12') }; eval { $v .= pmver('overload','any version') }; eval { $v .= pmver('strict','any version') }; eval { $v .= pmver('warnings','any version') }; # All done. $v .= <<'EOT'; Thanks for using my code. I hope it works for you. If not, please try and include this output in the bug report. That will help me reproduce the issue and solve you problem. EOT diag($v); ok(1, "we really didn't test anything, just reporting data"); $success = 1; # Work around another nasty module on CPAN. :/ no warnings 'once'; $Template::Test::NO_FLUSH = 1; exit 0; MooseX-MarkAsMethods-0.15/t/release-no-smart-comments.t0000644000175000017500000000114311761536207022041 0ustar cweylcweyl#!/usr/bin/env perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use strict; use warnings; use Test::More 0.88; eval "use Test::NoSmartComments"; plan skip_all => 'Test::NoSmartComments required for checking comment IQ' if $@; no_smart_comments_in_all(); done_testing(); MooseX-MarkAsMethods-0.15/t/release-consistent-version.t0000644000175000017500000000056211761536207022336 0ustar cweylcweyl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval "use Test::ConsistentVersion"; plan skip_all => "Test::ConsistentVersion required for this test" if $@; Test::ConsistentVersion::check_consistent_versions(); MooseX-MarkAsMethods-0.15/t/201_role_overload_using_class.t0000644000175000017500000000143611761536207022655 0ustar cweylcweyluse strict; use warnings; { package TestRole; use Moose::Role; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => sub { shift->stringify }, fallback => 1; #sub stringify { 'from role' } requires 'stringify'; has role_att => (isa => 'Str', is => 'rw'); } { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; with 'TestRole'; sub stringify { 'from class' } has class_att => (isa => 'Str', is => 'rw'); } use Test::More 0.92; #tests => XX; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', [ 'TestRole' ], [ qw{ role_att class_att } ], ); check_overloads($t, '""' => 'from class'); done_testing; MooseX-MarkAsMethods-0.15/t/105_via_method_name_with_fallback.t0000644000175000017500000000301611761536207023417 0ustar cweylcweyl#!/usr/bin/env perl # # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # ############################################################################# # # Author: Chris Weyl (cpan:RSRCHBOY), # Company: No company, personal work # # Copyright (c) 2009, 2010 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # ############################################################################# =head1 DESCRIPTION This test exercises overloading via method names (rather than a coderef), with a fallback. =cut use strict; use warnings; { package TestClass; use Moose; use MooseX::MarkAsMethods autoclean => 1; use overload q{""} => 'stringify', fallback => 1; has class_att => (isa => 'Str', is => 'rw', lazy_build => 1); sub _build_class_att { 'class_att value' } sub stringify { 'val: ' . shift->class_att } } use Test::More 0.92; use Test::Moose; require 't/funcs.pm' unless eval { require funcs }; check_sugar_removed_ok('TestClass'); my $t = make_and_check( 'TestClass', undef, [ 'class_att' ], ); check_overloads($t, '""' => 'val: class_att value'); done_testing; __END__ MooseX-MarkAsMethods-0.15/Makefile.PL0000644000175000017500000000247111761536207016367 0ustar cweylcweyl use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Mark overload code symbols as methods", "AUTHOR" => "Chris Weyl ", "BUILD_REQUIRES" => { "File::Find" => 0, "File::Temp" => 0, "Test::Moose" => 0, "Test::More" => "0.92", "overload" => 0 }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "MooseX-MarkAsMethods", "EXE_FILES" => [], "LICENSE" => "lgpl", "NAME" => "MooseX::MarkAsMethods", "PREREQ_PM" => { "B::Hooks::EndOfScope" => 0, "Moose" => "0.94", "Moose::Exporter" => 0, "Moose::Role" => 0, "Moose::Util::MetaRole" => 0, "namespace::autoclean" => "0.12", "strict" => 0, "warnings" => 0 }, "VERSION" => "0.15", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); MooseX-MarkAsMethods-0.15/lib/0000775000175000017500000000000011761536207015161 5ustar cweylcweylMooseX-MarkAsMethods-0.15/lib/MooseX/0000775000175000017500000000000011761536207016373 5ustar cweylcweylMooseX-MarkAsMethods-0.15/lib/MooseX/MarkAsMethods.pm0000644000175000017500000002261211761536207021434 0ustar cweylcweyl# # This file is part of MooseX-MarkAsMethods # # This software is Copyright (c) 2011 by Chris Weyl. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # package MooseX::MarkAsMethods; { $MooseX::MarkAsMethods::VERSION = '0.15'; } # ABSTRACT: Mark overload code symbols as methods use warnings; use strict; use namespace::autoclean 0.12; use B::Hooks::EndOfScope; use Moose 0.94 (); use Moose::Util::MetaRole; use Moose::Exporter; # debugging #use Smart::Comments '###', '####'; { package MooseX::MarkAsMethods::MetaRole::MethodMarker; { $MooseX::MarkAsMethods::MetaRole::MethodMarker::VERSION = '0.15'; } use Moose::Role; use namespace::autoclean; sub mark_as_method { my $self = shift @_; $self->_mark_as_method($_) for @_; return; } sub _mark_as_method { my ($self, $method_name) = @_; do { warn "$method_name is already a method!"; return } if $self->has_method($method_name); my $code = $self->get_package_symbol({ name => $method_name, sigil => '&', type => 'CODE', }); do { warn "$method_name not found as a CODE symbol!"; return } unless defined $code; $self->add_method($method_name => $self->wrap_method_body( associated_metaclass => $self, name => $method_name, body => $code, ), ); return; } } my ($import) = Moose::Exporter->build_import_methods( install => [ qw{ init_meta unimport } ], class_metaroles => { class => ['MooseX::MarkAsMethods::MetaRole::MethodMarker'], }, role_metaroles => { role => ['MooseX::MarkAsMethods::MetaRole::MethodMarker'], }, ); sub import { #my ($class, @args) = @_; my $class = shift @_; # if someone is passing in Sub::Exporter-style initial hash, grab it my $exporter_opts; $exporter_opts = shift @_ if ref $_[0] && ref $_[0] eq 'HASH'; my %args = @_; #my $target = $exporter_opts->{into} if $exporter_opts; #$target ||= scalar caller; my $target = defined $exporter_opts && defined $exporter_opts->{into} ? $exporter_opts->{into} : scalar caller ; return if $target eq 'main'; #$class->init_meta(for_class => $target); my $do_autoclean = delete $args{autoclean}; on_scope_end { ### $target my $meta = Class::MOP::Class->initialize($target); ### metaclass: ref $meta my %methods = map { ($_ => 1) } $meta->get_method_list; my %symbols = %{ $meta->get_all_package_symbols('CODE') }; my @overloads = grep { /^\(/ } keys %symbols; ### %methods ### %symbols ### @overloads foreach my $overload_name (@overloads) { next if $methods{$overload_name}; ### marking as method: $overload_name $meta->mark_as_method($overload_name); $methods{$overload_name} = 1; delete $symbols{$overload_name}; } return; }; ### $do_autoclean namespace::autoclean->import(-cleanee => $target) if $do_autoclean; @_ = $exporter_opts ? ($exporter_opts, %args) : (%args); unshift @_, $class; ### @_ goto &$import; return; } 1; =pod =encoding utf-8 =head1 NAME MooseX::MarkAsMethods - Mark overload code symbols as methods =head1 VERSION This document describes version 0.15 of MooseX::MarkAsMethods - released May 30, 2012 as part of MooseX-MarkAsMethods. =head1 SYNOPSIS package Foo; use Moose; # mark overloads as methods and wipe other non-methods use MooseX::MarkAsMethods autoclean => 1; # define overloads, etc as normal use overload '""' => sub { shift->stringify }; package Baz; use Moose::Role; use MooseX::MarkAsMethods autoclean => 1; # overloads defined in a role will "just work" when the role is # composed into a class; they MUST use the anon-sub style invocation use overload '""' => sub { shift->stringify }; # additional methods generated outside Class::MOP/Moose can be marked, too use constant foo => 'bar'; __PACKAGE__->meta->mark_as_method('foo'); package Bar; use Moose; # order is important! use namespace::autoclean; use MooseX::MarkAsMethods; # ... =head1 DESCRIPTION MooseX::MarkAsMethods allows one to easily mark certain functions as Moose methods. This will allow other packages such as L to operate without blowing away your overloads. After using MooseX::MarkAsMethods your overloads will be recognized by L as being methods, and class extension as well as composition from roles with overloads will "just work". By default we check for overloads, and mark those functions as methods. If C is passed to import on using this module, we will invoke namespace::autoclean to clear out non-methods. =for Pod::Coverage init_meta =head1 TRAITS APPLIED Using this package causes a trait to be applied to your metaclass (for both roles and classes), that provides a mark_as_method() method. You can use this to mark newly generated methods at runtime (e.g. during class composition) that some other package has created for you. mark_as_method() is invoked with one or more names to mark as a method. We die on any error (e.g. name not in symbol table, already a method, etc). e.g. __PACKAGE__->meta->mark_as_method('newly_generated'); e.g. say you have some sugar from another package that creates accessors of some sort; you could mark them as methods via a method modifier: # called as __PACKAGE__->foo_generator('name', ...) after 'foo_generator' => sub { shift->meta->mark_as_method(shift); }; =head1 IMPLICATIONS FOR ROLES Using MooseX::MarkAsMethods in a role will cause Moose to track and treat your overloads like any other method defined in the role, and things will "just work". That's it. Except... note that due to the way overloads, roles, and Moose work, you'll need to use the coderef or anonymous subroutine approach to overload declaration, or things will not work as you expect. Remember, we're talking about _methods_ here, so we need to make it easy for L to find the right method. The easiest (and supported) way to do this is to create an anonymous sub to wrap the overload method. That is, this will work: # note method resolution, things will "just work" use overload '""' => sub { shift->stringify }; ...and this will not: use overload '""' => 'stringify'; ...and will result in an error message like: # wah-wah Can't resolve method "???" overloading """" in package "overload" =head1 CAVEATS =head2 Roles See the "IMPLICATIONS FOR ROLES" section, above. =head2 meta->mark_as_method() B CMOP/Moose are fairly good about determining what is and what isn't a method, but not perfect. Before using this method, you should pause and think about why you need to. =head2 namespace::autoclean As currently implemented, we run our "method maker" at the end of the calling package's compile scope (L). As L does the same thing, it's important that if namespace::autoclean is used that it be used BEFORE MooseX::MarkAsMethods, so that its end_of_scope block is run after ours. e.g. # yes! use namespace::autoclean; use MooseX::MarkAsMethods; # no -- overloads will be removed use MooseX::MarkAsMethods; use namespace::autoclean; The easiest way to invoke this module and clean out non-methods without having to worry about ordering is: use MooseX::MarkAsMethods autoclean => 1; =head1 SEE ALSO Please see those modules/websites for more information related to this module. =over 4 =item * L, L, L, L,|L, L, L, L,> =item * L.|L.> =item * L does allow for overload application from|L does allow for overload application from> =item * L =item * L'ed role) the symbols handing overloads during class|L'ed role) the symbols handing overloads during class> =item * L =item * L =back =head1 SOURCE The development version is on github at L and may be cloned from L =head1 BUGS Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/moosex-markasmethods/issues When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR Chris Weyl =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2011 by Chris Weyl. This is free software, licensed under: The GNU Lesser General Public License, Version 2.1, February 1999 =cut __END__