Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean up the $path code

  • Loading branch information...
commit f6deca8384db88088dafbf78f50f0a6188ccee49 1 parent 3d9549c
@flussence authored
Showing with 11 additions and 10 deletions.
  1. +1 −7 bin/p6xmms2
  2. +10 −3 lib/XMMS2/Client.pm6
View
8 bin/p6xmms2
@@ -7,11 +7,5 @@ multi sub MAIN('play') {
}
sub client {
- # This is a hack because I don't know how to write "C NULL"
- my $path = (
- %*ENV<XMMS_PATH>,
- "unix:///tmp/xmms-ipc-{qx[whoami].trim}"
- ).first: *.so;
-
- return XMMS2::Client.new(:client-name<p6xmms2>, :$path);
+ return XMMS2::Client.new(:client-name<p6xmms2>);
}
View
13 lib/XMMS2/Client.pm6
@@ -21,11 +21,12 @@ class xmmsv_t is OpaquePointer;
class XMMS2::Client {
has xmmsc_connection_t $!connection;
- method new(Str $client_name = 'p6xmms2', Str $path = %*ENV<XMMS_PATH>) {
+ method new(Str $client_name = 'perl6-XMMS2', Str $path = self.default-path) {
self.bless(*, :$client_name, :$path);
}
method play returns Bool {
+ # TODO: code explodes somewhere on this line, .ok() apparently never gets reached
my Bool $success = self!ok: xmmsc_playback_start($!connection);
warn 'Playback start failed!' if not $success;
@@ -33,11 +34,15 @@ class XMMS2::Client {
return $success;
}
+ # Default path settings when calling code hasn't specified one
+ method default-path returns Str {
+ return %*ENV<XMMS_PATH> || "unix:///tmp/xmms-ipc-{qx[whoami].trim}";
+ }
+
# Check for error status from anything that returns an xmmsc_result_t.
# Also frees the result value.
method !ok(xmmsc_result_t $result) returns Bool {
my $command_status = xmmsc_result_get_value($result);
-
my $failed = xmmsv_is_error($command_status);
if $failed {
@@ -51,7 +56,9 @@ class XMMS2::Client {
# FIXME: libxmmsclient has this default $path, but you have to pass a C NULL value as the path
# to make it use it, which I don't know how to do using zavolaj yet.
- submethod BUILD(Str $client_name, Str $path = "unix:///tmp/xmms2-ipc-{qx[whoami].trim}") {
+ submethod BUILD(Str $client_name, Str $path) {
+ # FIXME: this can return NULL in an out-of-memory condition. No matter how implausible that
+ # might sound, it should still be checked...
$!connection = xmmsc_init($client_name);
xmmsc_connect($!connection, $path)
Please sign in to comment.
Something went wrong with that request. Please try again.