YaST::YCP - a binary interface between Perl and YCP
use YaST::YCP qw(:DATA :LOGGING);
YaST::YCP::Import ("SCR");
my $m = SCR->Read (".sysconfig.displaymanager.DISPLAYMANAGER");
SCR->Write (".sysconfig.kernel.CRASH_OFTEN", Boolean (1));
YaST has a richer and stricter data type system than Perl.
Note that the stdio-communicating agents, based on the modules YaST::SCRAgent and ycp, have a similar but not the same data type mapping.
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.
On the other hand, if the type is not known, expressed in YCP as any
, scalars will be passed as strings. If you want a specific data type, use one of the data classes like YaST::YCP::Integer. Of course these work also when the type is known.
Has only one value, nil
, which is represented as undef
. Any data type can have nil
as a value.
A union of all data types. Any data type can be assigned to it.
YCP to Perl: Becomes a scalar
Perl to YCP: Any scalar will become a string (even if it looks like a number). Use "String", "Integer", "Float" or "Boolean" if you want a specific data type.
YCP to Perl: A list becomes a reference to an array. (Note that it refers to a copy.)
Perl to YCP: A reference to an array becomes a list. This was different before SL9.1 Beta1: 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.
YCP to Perl: A map becomes a reference to a hash. (Note that it refers to a copy.)
Perl to YCP: A reference to a hash becomes a map.
YCP to Perl: NOT IMPLEMENTED YET.
Perl to YCP: If a path is expected, a scalar like ".foo.bar"
will be converted to .foo.bar
. Otherwise use "Path" (which is NOT IMPLEMENTED YET).
YCP to Perl: Becomes a "Symbol".
Perl to YCP: If a symbol is expected, a scalar like "foo"
will be converted to `foo
. Otherwise use "Symbol".
YCP to Perl: Becomes a "Term".
Perl to YCP: Use "Term".
YCP to Perl: Becomes a scalar.
Perl to YCP: If a byteblock is expected, a scalar like "\0\1"
will be converted to #[0001]
. Otherwise use "Byteblock".
Not implemented.
The DATA tag (in use YaST::YCP qw(:DATA)
) imports the data constructor functions such as Boolean, Symbol or Term.
$olddebug = YaST::YCP::debug (1);
YaST::YCP::...
YaST::YCP::debug ($olddebug);
Enables miscellaneous unscpecified debugging
YaST::YCP::init_ui ();
YaST::YCP::init_ui "qt";
Initializes the user interface, "ncurses" (the default) or "qt".
YaST::YCP::Import "Namespace";
Namespace->foo ("bar");
Imports a YaST namespace (in YCP or Perl or any supported language). Equivalent to YCP import
, similar to Perl use
.
If Namespace
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 Import
from a BEGIN
block.
These functions go via liby2util and thus use log.conf. See also ycp::y2milestone.
The multiple arguments are simply joined by a space.
y2debug ($message, $message2, ...)
y2milestone ($message, $message2, ...)
y2warning ($message, $message2, ...)
y2error ($message, $message2, ...)
y2security ($message, $message2, ...)
y2internal ($message, $message2, ...)
Implements the sformat YCP builtin:
sformat ('%2 %% %1', "a", "b")
returns 'b % a'
It is useful mainly for messages marked for translation.
$b = YaST::YCP::Boolean (1);
$b->value (0);
print $b->value, "\n";
SCR::Write (".foo", $b);
A chunk of binary data.
use YaST::YCP qw(:DATA);
read ($dev_random_fh, $r, 100);
$b = Byteblock ($r);
$b->value ("Hello\0world\0");
print $b->value, "\n";
return $b;
An explicitly typed integer, useful to put in heterogenous data structures.
use YaST::YCP qw(:DATA);
$i = Integer ("42 and more");
$i->value ("43, actually");
print $i->value, "\n";
return [ $i ];
An explicitly typed float, useful to put in heterogenous data structures.
use YaST::YCP qw(:DATA);
$f = Float ("3.41 is PI");
$f->value ("3.14 is PI");
print $f->value, "\n";
return [ $f ];
Not implemented yet.
An explicitly typed string, useful to put in heterogenous data structures.
use YaST::YCP qw(:DATA);
$s = String (42);
$s->value (1 + 1);
print $s->value, "\n";
return [ $s ];
use YaST::YCP qw(:DATA);
$s = Symbol ("next");
$s->value ("back");
print $s->value, "\n";
return Term ("id", $s);
$t = new YaST::YCP::Term("CzechBox", "Accept spam", new YaST::YCP::Boolean(0));
$t->name ("CheckBox");
print $t->args->[0], "\n";
UIx::OpenDialog ($t);