aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/perl/libkviperl.cpp
diff options
context:
space:
mode:
authorGravatar wodim2017-08-25 12:07:04 +0200
committerGravatar wodim2017-08-25 12:07:04 +0200
commitbff6c4d1d3b34e5c4c3fb83f9439b4427f75a363 (patch)
treed8ebbabf69b237556205b9d3f62ae50a1ce51652 /src/modules/perl/libkviperl.cpp
parentFix the text of all links in the documentation being lowercase. (diff)
downloadKVIrc-bff6c4d1d3b34e5c4c3fb83f9439b4427f75a363.tar.gz
KVIrc-bff6c4d1d3b34e5c4c3fb83f9439b4427f75a363.tar.bz2
KVIrc-bff6c4d1d3b34e5c4c3fb83f9439b4427f75a363.zip
Remove lots of redundant line feeds around block elements in the docs.
Diffstat (limited to 'src/modules/perl/libkviperl.cpp')
-rw-r--r--src/modules/perl/libkviperl.cpp60
1 files changed, 25 insertions, 35 deletions
diff --git a/src/modules/perl/libkviperl.cpp b/src/modules/perl/libkviperl.cpp
index 2284e7214..d84e1c848 100644
--- a/src/modules/perl/libkviperl.cpp
+++ b/src/modules/perl/libkviperl.cpp
@@ -71,13 +71,12 @@ static KviModule * g_pPerlCoreModule = nullptr;
@short:
How to use Perl from KVS and KVS from Perl.
@body:
- [big]Introduction[/big][br]
+ [big]Introduction[/big]
Starting from version 3.0.2 you can include Perl code snippets
in KVS code and you can use KVS commands from within Perl.
This feature is present only if a working Perl installation
- has been found at build time.[br]
- [br]
- [big]Using Perl from KVS[/big][br]
+ has been found at build time.
+ [big]Using Perl from KVS[/big]
Using Perl from KVIrc is really easy - just enclose
your Perl code snippet inside [cmd]perl.begin[/cmd] and [cmd]perl.end[/cmd].
[example]
@@ -85,7 +84,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
<perl code goes here>
[cmd]perl.end[/cmd]
[/example]
- For example:[br]
+ For example:
[example]
[cmd]perl.begin[/cmd]
open(MYFILE,'>>myfile.txt') or die "Can't open myfile.txt!";
@@ -98,9 +97,8 @@ static KviModule * g_pPerlCoreModule = nullptr;
and [cmd]perl.end[/cmd]. This means that you can write Perl code
in the commandline, in the aliases, the event handlers, popups...anywhere.[br]
If you have already encountered KVIrc's [cmd]eval[/cmd] command
- then you probably also know how to execute a Perl code snippet from a file :)[br]
- [br]
- [big]Using KVS from Perl[/big][br]
+ then you probably also know how to execute a Perl code snippet from a file :)
+ [big]Using KVS from Perl[/big]
KVIrc exports several commands to the Perl namespace
that allow you to invoke KVIrc's functions from inside the Perl code snippet.[br]
The nicest example is KVIrc::echo():
@@ -115,9 +113,8 @@ static KviModule * g_pPerlCoreModule = nullptr;
<text> is obviously the text to be printed. <colorset> is
the equivalent of the [cmd]echo[/cmd] -i option and <windowid>
is the equivalent of the -w option. Both <colorset> and <windowid>
- can be omitted (in this case KVIrc will use a default colorset and the current window).[br]
- [br]
- [big]Perl execution contexts[/big][br]
+ can be omitted (in this case KVIrc will use a default colorset and the current window).
+ [big]Perl execution contexts[/big]
The Perl code snippets are executed by a Perl interpreter - each
interpreter has its own context and thus its own variables,
own function namespace etc.[br]
@@ -128,7 +125,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
allow you to preserve your context across [cmd]perl.begin[/cmd] invocations.[br]
[br]
You can invoke a specific Perl context by passing it as parameter to the [cmd]perl.begin[/cmd]
- command:[br]
+ command:
[example]
[cmd]perl.begin("mycontext")[/cmd]
$myvariable = "mycontext";
@@ -136,7 +133,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
[cmd]perl.end[/cmd]
[/example]
The nice thing is that at a later time you can invoke this context again
- and discover that $mycontext has preserved its value:[br]
+ and discover that $mycontext has preserved its value:
[example]
[cmd]perl.begin("mycontext")[/cmd]
KVIrc::echo("myvariable is still equal to ".$myvariable);
@@ -167,23 +164,21 @@ static KviModule * g_pPerlCoreModule = nullptr;
once in a while to recreate the interpreter.[br]
If you just execute occasional Perl code snippets and don't need to keep
persistent variables, then just use the nameless temporary context provided
- by [cmd]perl.begin[/cmd]("").[br]
- [br]
- [big]Passing parameters to the Perl script[/big][br]
+ by [cmd]perl.begin[/cmd]("").
+ [big]Passing parameters to the Perl script[/big]
The easiest way to pass parameters to the perl code snippet
is to put them as [cmd]perl.begin[/cmd] arguments.
In fact the complete syntax of [cmd]perl.begin[/cmd] is:[br]
[b]perl.begin(<perl context>,<arg0>,<arg1>,...)[/b][br]
Where the <arg0>,<arg1>...<argN> parameters
- are passed to the Perl context as elements of the $_[] array.[br]
+ are passed to the Perl context as elements of the $_[] array.
[example]
[cmd]perl.begin[/cmd]("","Hello world!","Now I CAN",1,2,3)
for($i=0;$i<5;$i++)
KVIrc::echo($_[i],40);
[cmd]perl.end[/cmd]
[/example]
- [br]
- [big]Accessing the KVIrc scripting context from Perl[/big][br]
+ [big]Accessing the KVIrc scripting context from Perl[/big]
KVIrc exposes the following functions that manipulate
variables of the KVIrc's current KVS execution context:[br]
&nbsp; &nbsp; [b]KVIrc::getLocal(&lt;x&gt;)[/b][br]
@@ -195,7 +190,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
&nbsp; &nbsp; [b]KVIrc::setGlobal(&lt;Y&gt;,&lt;value&gt;)[/b][br]
Sets KVIrc's global variable %Y to &lt;value&gt;[br]
The local variables referenced belong to the current KVS execution context
- while the global variables are visible everywhere.[br]
+ while the global variables are visible everywhere.
[example]
%pippo = test
%Pluto = 12345
@@ -210,13 +205,12 @@ static KviModule * g_pPerlCoreModule = nullptr;
[cmd]echo[/cmd] "\%pippo is" %pippo
[cmd]echo[/cmd] "\%Pluto is" %Pluto
[/example]
- [br]
- [big]Executing arbitrary KVIrc commands from Perl[/big][br]
+ [big]Executing arbitrary KVIrc commands from Perl[/big]
You can execute arbitrary KVS commands from Perl by means of:[br]
&nbsp; &nbsp; [b]KVIrc::eval(&lt;code&gt;)[/b][br]
This function behaves exactly like the ${ &lt;code&gt; } KVS construct -
it executes &lt;code&gt; in a child context and returns its evaluation result.[br]
- The following two code snippets have equivalent visible effects:[br]
+ The following two code snippets have equivalent visible effects:
[example]
[cmd]echo[/cmd] ${ return "Yeah!"; }
[/example]
@@ -228,7 +222,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
You can [i]eval[/i] compound command sequences and variable ones.[br]
Remember that the Perl code snippet is evaluated in a child KVS context
and thus the local variables are NOT visible!
- The following code snippets may easily fool you:[br]
+ The following code snippets may easily fool you:
[example]
%x = 10
[cmd]perl.begin[/cmd]
@@ -236,7 +230,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
[cmd]perl.end[/cmd]
[/example]
This will print [i]The value is[/i] since %x is not accessible from the eval's context.
- If you have tried to write something like this then you probably need to rewrite it as:[br]
+ If you have tried to write something like this then you probably need to rewrite it as:
[example]
%x = 10
[cmd]perl.begin[/cmd]
@@ -257,7 +251,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
KVIrc::echo(KVIrc::eval('return $window.caption'));
[cmd]perl.end[/cmd]
[/example]
- [big]A shortcut for KVIrc::eval("/say...")[/big][br]
+ [big]A shortcut for KVIrc::eval("/say...")[/big]
Since KVIrc::eval("/say...") is a common calling pattern, say has been added
to the KVIrc Perl namespace. You can now call
[example]
@@ -270,8 +264,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
The complete syntax for KVIrc::say() is:[br]
&nbsp; &nbsp; [b]KVIrc::say(&lt;text&gt;[,&lt;windowid&gt;])[/b][br]
and the semantics are obvious (see also /[cmd]say[/cmd]).
- [br]
- [big]Perl script return values[/big][br]
+ [big]Perl script return values[/big]
The [cmd]perl.begin[/cmd] command propagates the Perl code return
value to the KVIrc context (just like a [cmd]setreturn[/cmd]() would do)
- this makes it easier to create an alias that executes a Perl script and
@@ -284,8 +277,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
[li]Then, from the KVIrc script after [cmd]perl.end[/cmd], retrieve the
%var variable, check its value and call [cmd]setreturn[/cmd]() on it.[/li]
[/ul]
- [br]
- [big]Executing Perl scripts from files[/big][br]
+ [big]Executing Perl scripts from files[/big]
[example]
[cmd]alias[/cmd](perlexec)
{
@@ -298,13 +290,12 @@ static KviModule * g_pPerlCoreModule = nullptr;
[comment]# or even[/comment]
[cmd]echo[/cmd] $perlexec("/home/pragma/computeprimelargerthan.pl","10000")
[/example]
- [br]
- [big]Other tricks[/big][br]
+ [big]Other tricks[/big]
An interesting feature of persistent Perl contexts is that you can prepare a
context for later fast execution.[br]
The idea is to declare all Perl functions in a single Perl code snippet
then call single functions when fast execution is needed.[br]
- For example you might parse the following snippet at KVIrc's startup:[br]
+ For example you might parse the following snippet at KVIrc's startup:
[example]
[cmd]perl.begin[/cmd]("persistent")
sub handler_for_event_1
@@ -323,8 +314,7 @@ static KviModule * g_pPerlCoreModule = nullptr;
handler_for_event_1($_[0],$_[1])
[cmd]perl.end[/cmd]
[/example]
- [br]
- [big]Curiosity[/big][br]
+ [big]Curiosity[/big]
The Perl support in KVIrc is implemented as a master-slave module pair.
The perl.* module is the master while perlcore is the slave.
When Perl support isn't compiled in, the perl.* commands