NAME

YaST::YCP - a binary interface between Perl and YCP


SYNOPSIS

 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));


DATA TYPES

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.

void
Has only one value, nil, which is represented as undef. Any data type can have nil as a value.

any
A union of all data types. Any data type can be assigned to it.

string, integer, float, boolean
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.

list <T>
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.

map <T1, T2>
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.

path
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).

symbol
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.

term
YCP to Perl: Becomes a Term.

Perl to YCP: Use Term.

byteblock
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.

locale, block <T>, ...
Not implemented.


YaST::YCP

The DATA tag (in use YaST::YCP qw(:DATA)) imports the data constructor functions such as Boolean, Symbol or Term.

debug

 $olddebug = YaST::YCP::debug (1);
 YaST::YCP::...
 YaST::YCP::debug ($olddebug);

Enables miscellaneous unscpecified debugging

init_ui

 YaST::YCP::init_ui ();
 YaST::YCP::init_ui "qt";

Initializes the user interface, ``ncurses'' (the default) or ``qt''.

Import

 YaST::YCP::Import "Namespace";
 Namespace->foo ("bar");

logging

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, ...)

sformat

Implements the sformat YCP builtin:

sformat ('%2 %% %1', "a", "b") returns 'b % a'

It is useful mainly for messages marked for translation.

Boolean

 $b = YaST::YCP::Boolean (1);
 $b->value (0);
 print $b->value, "\n";
 SCR::Write (".foo", $b);

Byteblock

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;

Integer

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 ];

Float

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 ];

Path

Not implemented yet.

String

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 ];

Symbol

 use YaST::YCP qw(:DATA);
 $s = Symbol ("next");
 $s->value ("back");
 print $s->value, "\n";
 return Term ("id", $s);

Term

 $t = new YaST::YCP::Term("CzechBox", "Accept spam", new YaST::YCP::Boolean(0));
 $t->name ("CheckBox");
 print $t->args->[0], "\n";
 UIx::OpenDialog ($t);