|
|
| |
self::init(3) |
User Contributed Perl Documentation |
self::init(3) |
self::init - Invoke package init methods at compile time
# At compile time
use self::init
\-x => qw( y z ), # same as BEGIN { CLASS->x('y','z'); }
;
# At runtime
self::init
\-a => qw(a b),
\-b => (),
\-c => qw( c c ),
;
# Same as
CLASS->a('a','v');
CLASS->b();
CLASS->c('c','c');
# With bad arguments (scalarrefs, containing string, beginning from -)
self::init
[ a => \'-arg1', \'-arg2' ],
[ b => 'arg3', 'arg4' ],
;
# ! Warning!
# Mixed syntax is not allowed
self::init
\-a => qw(arg1 arg2),
[ b => \'-arg1', \'-arg2' ],
;
# will be invoked as
CLASS->a('arg1','arg2', [ 'b', \'-arg1', \'-arg2' ] );
# So be aware
This module is just a helper to avoid repetiotion of ugly
__PACKAGE__->method();
- self::init pragma
-
use self::init ARGS;
- self::init statement
-
self::init ARGS;
- ARGS
- Synopsis 1:
Method name is constructed as a reference to string,
containing method name, prefixed with '-'. Rest in list is threated as
arguments to that method, until next method name or end of whole
statement. So, if your arguments not written by hand or in some way
could receive value of SCALARREF, containing string, beginning from -,
invocation will be wrong (see Synopsis 2)
When writing method names not quoted (hash key bareword), the
whole statement looks like an ASCII tree, where methods are descendants
of self::init ;)
self::init
\-method1 => (1,2,3),
\-method_another => ('some', 'args'),
\-_private_method => (), # no args,
# so on
;
Synopsis 2:
Single method invocation is constructed as ARRAYREF,
containing first element as method name and rest as arguments. It is
reliable to any arguments, but don't mix both synopsises in a single
call
self::init
[ method1 => 1,2,3 ],
[ method_another => 'some', 'args' ],
[ _private_method => (), ], # no args
# so on
;
Mons Anderson, <mons@cpan.org>
Copyright 2009 Mons Anderson.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. Output converted with ManDoc. |