.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" 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" '' . ds C` . ds C' '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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MakeMethods::Template::Universal 3pm" .TH MakeMethods::Template::Universal 3pm "2016-06-10" "perl v5.22.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" Class::MakeMethods::Template::Universal \- Meta\-methods for any type of object .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& package MyObject; \& use Class::MakeMethods::Template::Universal ( \& \*(Aqno_op\*(Aq => [ \*(Aqtwiddle\*(Aq ], \& \*(Aqcroak\*(Aq => [ \*(Aqfail\*(Aq, { croak_msg => \*(AqCurses!\*(Aq } ] \& ); \& \& package main; \& \& MyObject\->twiddle; # Does nothing \& if ( $foiled ) { MyObject\->fail() } # Dies with croak_msg .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" .SH "UNIVERSAL META-METHODS" .IX Header "UNIVERSAL META-METHODS" The following meta-methods and behaviors are applicable across multiple types of classes and objects. .SS "Universal:generic" .IX Subsection "Universal:generic" This is not a directly-invokable method type, but instead provides code expressions for use in other method-generators. .PP You can use any of these features in your meta-method interfaces without explicitly importing them. .PP \&\fBModifiers\fR .IP "\(bu" 4 \&\-\-private .Sp Causes the method to croak if it is called from outside of the package which originally declared it. .Sp Note that this protection can currently be circumvented if your class provides the method_init behavior, or another subroutine that calls methods by name. .IP "\(bu" 4 \&\-\-protected .Sp Causes the method to croak if it is called from a package other than the declaring package and its inheritors. .Sp Note that this protection can currently be circumvented if your class provides the method_init behavior, or another subroutine that calls methods by name. .IP "\(bu" 4 \&\-\-public .Sp Cancels any previous \-private or \-protected declaration. .IP "\(bu" 4 \&\-\-self_closure .Sp Causes the method to return a function reference which is bound to the arguments provided when it is first called. .Sp For examples of usage, see the test scripts in t/*closure.t. .IP "\(bu" 4 \&\-\-lvalue .Sp Adds the \*(L":lvalue\*(R" attribute to the subroutine declaration. .Sp For examples of usage, see the test scripts in t/*lvalue.t. .IP "\(bu" 4 \&\-\-warn_calls .Sp For diagnostic purposes, call warn with the object reference, method name, and arguments before executing the body of the method. .PP \&\fBBehaviors\fR .IP "\(bu" 4 attributes .Sp Runtime access to method parameters. .IP "\(bu" 4 no_op \*(-- See below. .IP "\(bu" 4 croak \*(-- See below. .IP "\(bu" 4 method_init \*(-- See below. .SS "no_op" .IX Subsection "no_op" For each meta-method, creates a method with an empty body. .PP .Vb 3 \& use Class::MakeMethods::Template::Universal ( \& \*(Aqno_op\*(Aq => [ \*(Aqfoo bar baz\*(Aq ], \& ); .Ve .PP You might want to create and use such methods to provide hooks for subclass activity. .PP No interfaces or parameters supported. .SS "croak" .IX Subsection "croak" For each meta-method, creates a method which will croak if called. .PP .Vb 3 \& use Class::MakeMethods::Template::Universal ( \& \*(Aqcroak\*(Aq => [ \*(Aqfoo bar baz\*(Aq ], \& ); .Ve .PP This is intended to support the use of abstract methods, that must be overridden in a useful subclass. .PP If each subclass is expected to provide an implementation of a given method, using this abstract method will replace the generic error message below with the clearer, more explicit error message that follows it: .PP .Vb 2 \& Can\*(Aqt locate object method "foo" via package "My::Subclass" \& The "foo" method is abstract and can not be called on My::Subclass .Ve .PP However, note that the existence of this method will be detected by \fIUNIVERSAL::can()\fR, so it is not suitable for use in optional interfaces, for which you may wish to be able to detect whether the method is supported or not. .PP The \-unsupported and \-prohibited interfaces provide alternate error messages, or a custom error message can be provided using the \&'croak_msg' parameter. .SS "method_init" .IX Subsection "method_init" Creates a method that accepts a hash of key-value pairs, or a reference to hash of such pairs. For each pair, the key is interpreted as the name of a method to call, and the value is the argument to be passed to that method. .PP Sample declaration and usage: .PP .Vb 5 \& package MyObject; \& use Class::MakeMethods::Template::Universal ( \& method_init => \*(Aqinit\*(Aq, \& ); \& ... \& \& my $object = MyObject\->new() \& $object\->init( foo => \*(AqFoozle\*(Aq, bar => \*(AqBarbados\*(Aq ); \& \& # Equivalent to: \& $object\->foo(\*(AqFoozle\*(Aq); \& $object\->bar(\*(AqBarbados\*(Aq); .Ve .PP You might want to create and use such methods to allow easy initialization of multiple object or class parameters in a single call. .PP \&\fBNote\fR: including methods of this type will circumvent the protection of \f(CW\*(C`private\*(C'\fR and \f(CW\*(C`protected\*(C'\fR methods, because it an outside caller can cause an object to call specific methods on itself, bypassing the privacy protection. .SS "forward_methods" .IX Subsection "forward_methods" Creates a method which delegates to an object provided by another method. .PP Example: .PP .Vb 6 \& use Class::MakeMethods::Template::Universal \& forward_methods => [ \& \-\-target=> \*(Aqwhistle\*(Aq, w, \& [ \*(Aqx\*(Aq, \*(Aqy\*(Aq ], { target=> \*(Aqxylophone\*(Aq }, \& { name=>\*(Aqz\*(Aq, target=>\*(Aqzither\*(Aq, target_args=>[123], method_name=>do_zed }, \& ]; .Ve .PP Example: The above defines that method \f(CW\*(C`w\*(C'\fR will be handled by the calling \f(CW\*(C`w\*(C'\fR on the object returned by \f(CW\*(C`whistle\*(C'\fR, whilst methods \f(CW\*(C`x\*(C'\fR and \f(CW\*(C`y\*(C'\fR will be handled by \f(CW\*(C`xylophone\*(C'\fR, and method \f(CW\*(C`z\*(C'\fR will be handled by calling \f(CW\*(C`do_zed\*(C'\fR on the object returned by calling \f(CW\*(C`zither(123)\*(C'\fR. .PP \&\fBInterfaces\fR: .IP "forward (default)" 4 .IX Item "forward (default)" Calls the method on the target object. If the target object is missing, croaks at runtime with a message saying \*(L"Can't forward bar because bar is empty.\*(R" .IP "delegate" 4 .IX Item "delegate" Calls the method on the target object, if present. If the target object is missing, returns nothing. .PP \&\fBParameters\fR: The following additional parameters are supported: .IP "target" 4 .IX Item "target" \&\fIRequired\fR. The name of the method that will provide the object that will handle the operation. .IP "target_args" 4 .IX Item "target_args" Optional ref to an array of arguments to be passed to the target method. .IP "method_name" 4 .IX Item "method_name" The name of the method to call on the handling object. Defaults to the name of the meta-method being created. .SH "SEE ALSO" .IX Header "SEE ALSO" See Class::MakeMethods for general information about this distribution. .PP See Class::MakeMethods::Template for information about this family of subclasses.