ACC SHELL
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YaST::YCP - a binary interface between Perl and YCP</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:feedback@suse.de" />
</head>
<body style="background-color: white">
<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#data_types">DATA TYPES</a></li>
<li><a href="#yast__ycp">YaST::YCP</a></li>
<ul>
<li><a href="#debug">debug</a></li>
<li><a href="#init_ui">init_ui</a></li>
<li><a href="#import">Import</a></li>
<li><a href="#logging">logging</a></li>
<li><a href="#sformat">sformat</a></li>
<li><a href="#boolean">Boolean</a></li>
<li><a href="#byteblock">Byteblock</a></li>
<li><a href="#integer">Integer</a></li>
<li><a href="#float">Float</a></li>
<li><a href="#path">Path</a></li>
<li><a href="#string">String</a></li>
<li><a href="#symbol">Symbol</a></li>
<li><a href="#term">Term</a></li>
</ul>
</ul>
<hr name="index" />
</div>
<!-- INDEX END -->
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>YaST::YCP - a binary interface between Perl and YCP</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
use YaST::YCP qw(:DATA :LOGGING);</pre>
<pre>
YaST::YCP::Import ("SCR");
my $m = SCR->Read (".sysconfig.displaymanager.DISPLAYMANAGER");
SCR->Write (".sysconfig.kernel.CRASH_OFTEN", Boolean (1));</pre>
<p>
</p>
<hr />
<h1><a name="data_types">DATA TYPES</a></h1>
<p>YaST has a richer and stricter data type system than Perl.</p>
<p>Note that the stdio-communicating agents, based on the modules
<a href="/YaST/SCRAgent.html">YaST::SCRAgent</a> and <em>ycp</em>, have a similar but
not the same data type mapping.</p>
<p>When the language binding knows what type to expect, eg. when passing
an argument to a YCP function, it will convert a Perl scalar to the
desired type.</p>
<p>On the other hand, if the type is not known, expressed
in YCP as <a href="#any"><code>any</code></a>, scalars will be passed as strings. If you want
a specific data type, use one of the data classes like
<a href="#integer">YaST::YCP::Integer</a>. Of course these work also when
the type is known.</p>
<dl>
<dt><strong><a name="void" class="item">void</a></strong>
<dd>
<p>Has only one value, <code>nil</code>, which is represented as <code>undef</code>.
Any data type can have <code>nil</code> as a value.</p>
</dd>
</li>
<dt><strong><a name="any" class="item">any</a></strong>
<dd>
<p>A union of all data types. Any data type can be assigned to it.</p>
</dd>
</li>
<dt><strong><a name="string_integer_float_boolean" class="item">string, integer, float, boolean</a></strong>
<dd>
<p><strong>YCP to Perl:</strong> Becomes a scalar</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> Any scalar will become a string
(even if it looks like a number).
Use <a href="#string">String</a>, <a href="#integer">Integer</a>, <a href="#float">Float</a> or <a href="#boolean">Boolean</a>
if you want a specific data type.</p>
</dd>
</li>
<dt><strong><a name="list_t" class="item">list <T></a></strong>
<dd>
<p><strong>YCP to Perl:</strong> A list becomes a reference to an array.
(Note that it refers to a <strong>copy</strong>.)</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> A reference to an array becomes a list.
<em>This was different before SL9.1 Beta1:</em>
Perl functions returning multiple values should not return a list
but a reference to it. YCP will always set a scalar calling context,
even if the result is assigned to a list.</p>
</dd>
</li>
<dt><strong><a name="map_t1_t2" class="item">map <T1, T2></a></strong>
<dd>
<p><strong>YCP to Perl:</strong> A map becomes a reference to a hash.
(Note that it refers to a <strong>copy</strong>.)</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> A reference to a hash becomes a map.</p>
</dd>
</li>
<dt><strong><a name="path" class="item">path</a></strong>
<dd>
<p><strong>YCP to Perl:</strong> NOT IMPLEMENTED YET.</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> If a path is expected, a scalar like <code>".foo.bar"</code>
will be converted to <code>.foo.bar</code>.
Otherwise use <a href="#path">Path</a> (which is NOT IMPLEMENTED YET).</p>
</dd>
</li>
<dt><strong><a name="symbol" class="item">symbol</a></strong>
<dd>
<p><strong>YCP to Perl:</strong> Becomes a <a href="#symbol">Symbol</a>.</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> If a symbol is expected, a scalar like <code>"foo"</code>
will be converted to <code>`foo</code>.
Otherwise use <a href="#symbol">Symbol</a>.</p>
</dd>
</li>
<dt><strong><a name="term" class="item">term</a></strong>
<dd>
<p><strong>YCP to Perl:</strong> Becomes a <a href="#term">Term</a>.</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> Use <a href="#term">Term</a>.</p>
</dd>
</li>
<dt><strong><a name="byteblock" class="item">byteblock</a></strong>
<dd>
<p><strong>YCP to Perl:</strong> Becomes a scalar.</p>
</dd>
<dd>
<p><strong>Perl to YCP:</strong> If a byteblock is expected, a scalar like <code>"\0\1"</code>
will be converted to <code>#[0001]</code>.
Otherwise use <a href="#byteblock">Byteblock</a>.</p>
</dd>
</li>
<dt><strong><a name="locale_block_t" class="item">locale, block <T>, ...</a></strong>
<dd>
<p>Not implemented.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="yast__ycp">YaST::YCP</a></h1>
<p>The DATA tag (in <code>use YaST::YCP qw(:DATA)</code>) imports the data
constructor functions such as Boolean, Symbol or Term.</p>
<p>
</p>
<h2><a name="debug">debug</a></h2>
<pre>
$olddebug = YaST::YCP::debug (1);
YaST::YCP::...
YaST::YCP::debug ($olddebug);</pre>
<p>Enables miscellaneous unscpecified debugging</p>
<p>
</p>
<h2><a name="init_ui">init_ui</a></h2>
<pre>
YaST::YCP::init_ui ();
YaST::YCP::init_ui "qt";</pre>
<p>Initializes the user interface, "ncurses" (the default) or "qt".</p>
<p>
</p>
<h2><a name="import">Import</a></h2>
<pre>
YaST::YCP::Import "Namespace";
Namespace->foo ("bar");</pre>
<p>Imports a YaST namespace (in YCP or Perl or any supported language).
Equivalent to YCP <code>import</code>, similar to Perl <code>use</code>.</p>
<p>If <code>Namespace</code> is in YCP, its constructor is executed later than if
it were imported from YCP. This can have subtle effects, for example
in testsuites. To get closer to the YCP import behavior, call
<code>Import</code> from a <code>BEGIN</code> block.</p>
<p>
</p>
<h2><a name="logging">logging</a></h2>
<p>These functions go via liby2util and thus use log.conf.
See also ycp::y2milestone.</p>
<p>The multiple arguments are simply joined by a space.</p>
<pre>
y2debug ($message, $message2, ...)
y2milestone ($message, $message2, ...)
y2warning ($message, $message2, ...)
y2error ($message, $message2, ...)
y2security ($message, $message2, ...)
y2internal ($message, $message2, ...)</pre>
<p>
</p>
<h2><a name="sformat">sformat</a></h2>
<p>Implements the sformat YCP builtin:</p>
<p><code>sformat ('%2 %% %1', "a", "b")</code> returns <code>'b % a'</code></p>
<p>It is useful mainly for messages marked for translation.</p>
<p>
</p>
<h2><a name="boolean">Boolean</a></h2>
<pre>
$b = YaST::YCP::Boolean (1);
$b->value (0);
print $b->value, "\n";
SCR::Write (".foo", $b);</pre>
<p>
</p>
<h2><a name="byteblock">Byteblock</a></h2>
<p>A chunk of binary data.</p>
<pre>
use YaST::YCP qw(:DATA);</pre>
<pre>
read ($dev_random_fh, $r, 100);
$b = Byteblock ($r);
$b->value ("Hello\0world\0");
print $b->value, "\n";
return $b;</pre>
<p>
</p>
<h2><a name="integer">Integer</a></h2>
<p>An explicitly typed integer, useful to put in heterogenous data structures.</p>
<pre>
use YaST::YCP qw(:DATA);</pre>
<pre>
$i = Integer ("42 and more");
$i->value ("43, actually");
print $i->value, "\n";
return [ $i ];</pre>
<p>
</p>
<h2><a name="float">Float</a></h2>
<p>An explicitly typed float, useful to put in heterogenous data structures.</p>
<pre>
use YaST::YCP qw(:DATA);</pre>
<pre>
$f = Float ("3.41 is PI");
$f->value ("3.14 is PI");
print $f->value, "\n";
return [ $f ];</pre>
<p>
</p>
<h2><a name="path">Path</a></h2>
<p>Not implemented yet.</p>
<p>
</p>
<h2><a name="string">String</a></h2>
<p>An explicitly typed string, useful to put in heterogenous data structures.</p>
<pre>
use YaST::YCP qw(:DATA);</pre>
<pre>
$s = String (42);
$s->value (1 + 1);
print $s->value, "\n";
return [ $s ];</pre>
<p>
</p>
<h2><a name="symbol">Symbol</a></h2>
<pre>
use YaST::YCP qw(:DATA);</pre>
<pre>
$s = Symbol ("next");
$s->value ("back");
print $s->value, "\n";
return Term ("id", $s);</pre>
<p>
</p>
<h2><a name="term">Term</a></h2>
<pre>
$t = new YaST::YCP::Term("CzechBox", "Accept spam", new YaST::YCP::Boolean(0));
$t->name ("CheckBox");
print $t->args->[0], "\n";
UIx::OpenDialog ($t);</pre>
</body>
</html>
ACC SHELL 2018