.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooseX::MarkAsMethods 3pm" .TH MooseX::MarkAsMethods 3pm "2012-05-31" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooseX::MarkAsMethods \- Mark overload code symbols as methods .SH "VERSION" .IX Header "VERSION" This document describes version 0.15 of MooseX::MarkAsMethods \- released May 30, 2012 as part of MooseX-MarkAsMethods. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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 \*(Aq""\*(Aq => 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 \*(Aq""\*(Aq => sub { shift\->stringify }; \& \& # additional methods generated outside Class::MOP/Moose can be marked, too \& use constant foo => \*(Aqbar\*(Aq; \& _\|_PACKAGE_\|_\->meta\->mark_as_method(\*(Aqfoo\*(Aq); \& \& package Bar; \& use Moose; \& \& # order is important! \& use namespace::autoclean; \& use MooseX::MarkAsMethods; \& \& # ... .Ve .SH "DESCRIPTION" .IX Header "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 \*(L"just work\*(R". .PP By default we check for overloads, and mark those functions as methods. .PP If \f(CW\*(C`autoclean => 1\*(C'\fR is passed to import on using this module, we will invoke namespace::autoclean to clear out non-methods. .SH "TRAITS APPLIED" .IX Header "TRAITS APPLIED" Using this package causes a trait to be applied to your metaclass (for both roles and classes), that provides a \fImark_as_method()\fR 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. .PP \&\fImark_as_method()\fR 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. .PP .Vb 1 \& _\|_PACKAGE_\|_\->meta\->mark_as_method(\*(Aqnewly_generated\*(Aq); .Ve .PP 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: .PP .Vb 2 \& # called as _\|_PACKAGE_\|_\->foo_generator(\*(Aqname\*(Aq, ...) \& after \*(Aqfoo_generator\*(Aq => sub { \& \& shift\->meta\->mark_as_method(shift); \& }; .Ve .SH "IMPLICATIONS FOR ROLES" .IX Header "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 \*(L"just work\*(R". That's it. .PP 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. .PP That is, this will work: .PP .Vb 2 \& # note method resolution, things will "just work" \& use overload \*(Aq""\*(Aq => sub { shift\->stringify }; .Ve .PP \&...and this will not: .PP .Vb 1 \& use overload \*(Aq""\*(Aq => \*(Aqstringify\*(Aq; .Ve .PP \&...and will result in an error message like: .PP .Vb 2 \& # wah\-wah \& Can\*(Aqt resolve method "???" overloading """" in package "overload" .Ve .SH "CAVEATS" .IX Header "CAVEATS" .SS "Roles" .IX Subsection "Roles" See the \*(L"\s-1IMPLICATIONS\s0 \s-1FOR\s0 \s-1ROLES\s0\*(R" section, above. .SS "meta\->\fImark_as_method()\fP" .IX Subsection "meta->mark_as_method()" \&\fBYou almost certainly don't need or want to do this.\fR 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. .SS "namespace::autoclean" .IX Subsection "namespace::autoclean" As currently implemented, we run our \*(L"method maker\*(R" 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 \s-1BEFORE\s0 MooseX::MarkAsMethods, so that its end_of_scope block is run after ours. .PP e.g. .PP .Vb 3 \& # yes! \& use namespace::autoclean; \& use MooseX::MarkAsMethods; \& \& # no \-\- overloads will be removed \& use MooseX::MarkAsMethods; \& use namespace::autoclean; .Ve .PP The easiest way to invoke this module and clean out non-methods without having to worry about ordering is: .PP .Vb 1 \& use MooseX::MarkAsMethods autoclean => 1; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Please see those modules/websites for more information related to this module. .IP "\(bu" 4 overload, B::Hooks::EndOfScope, namespace::autoclean, Class::MOP, .IP "\(bu" 4 Moose. .IP "\(bu" 4 MooseX::Role::WithOverloading does allow for overload application from .IP "\(bu" 4 roles, but it does this by copying the overload symbols from the (not .IP "\(bu" 4 namespace::autoclean'ed role) the symbols handing overloads during class .IP "\(bu" 4 composition; we work by marking the overloads as methods and letting .IP "\(bu" 4 CMOP/Moose handle them. .SH "SOURCE" .IX Header "SOURCE" The development version is on github at http://github.com/RsrchBoy/moosex\-markasmethods and may be cloned from git://github.com/RsrchBoy/moosex\-markasmethods.git .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/moosex\-markasmethods/issues .PP 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. .SH "AUTHOR" .IX Header "AUTHOR" Chris Weyl .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2011 by Chris Weyl. .PP This is free software, licensed under: .PP .Vb 1 \& The GNU Lesser General Public License, Version 2.1, February 1999 .Ve