This file is indexed.

/usr/share/perl5/Audio/Moosic.pm is in libaudio-moosic-perl 0.10-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
package Audio::Moosic;

use strict;
use warnings;
use vars qw( $VERSION );
use RPC::XML;
use RPC::XML::Client;

$VERSION = '0.10';

=head1 NAME

Audio::Moosic - Moosic client library for Perl

=head1 SYNOPSIS

  use Audio::Moosic;

  $moo = Audio::Moosic::Unix->new();

  $moosic->append('/home/me/somewhat.ogg');
  $moosic->play;
  print $moosic->current, "\n";
  $moosic->pause;
  ...

=head1 DESCRIPTION

Audio::Moosic acts as a client for the musical jukebox programm Moosic
(http://nanoo.org/~daniel/moosic/) by Daniel Pearson <daniel@nanoo.org>.

Using Audio::Moosic you can connect to a moosic server either via an UNIX socket
or an INET socket.

=head1 METHODS

=head2 new

  $moo = Audio::Moosic::Unix->new();
  $moo = Audio::Moosic::Unix->new('/tmp/moosic/socket');
  $moo = Audio::Moosic::Inet->new('localhost', 8765);

Constructor. Initializes the class and invokes the connect method. If you're
creating a Audio::Moosic::Unix object you can give the location of your moosic
socket as parameter. If not ~/.moosic/socket is used. If you're creating a
Audio::Moosic::Inet instance you need to pass host and port as arguments.

You can't create an instance of Audio::Moosic itself. Use Unix or Inet subclass.

If the object was able to connect to the moosic server a reference to the object
instance is returned. If the connection failed $@ is set and undef returned.

=cut

sub new {
    my ($class, @args) = @_;
    $class = ref($class) || $class;

    my $self = { __errors => [ ] };
    bless $self, $class;

    unless( $self->connect(@args) ) {
        $@ = "Can't connect to moosic server: $!";
        return;
    }

    return $self;
}

=head2 connect

  $moo->connect('foobar.com', 9876);

Connect to the moosic server. You normally don't need to run this method in your
moosic client.

=cut

sub connect {
    require Carp;
    Carp::croak('This method should never be called. Please create an instance'.
                ' of Audio::Moosic::Inet or Audio::Moosic::Unix.');
}

=head2 disconnect

  $moo->disconnect;

Disconnect from the moosic daemon. No more calls will be sent to the server
after calling this method. You'll need to reconnect() first.

=cut

sub disconnect {
    my $self = shift;
    $self->{__connected} = 0;
    delete $self->{__rpc_xml_client};
}

=head2 reconnect

  $moo->reconnect;

Disconnects from the server if you're connected and tries to reconnect.

=cut

sub reconnect {
    my $self = shift;
    $self->disconnect if $self->connected;
    return $self->connect;
}

=head2 connected

  $moo->reconnect unless $moo->connected;

Check whether you're connected to the moosic server or not.

=cut

sub connected {
    my $self = shift;
    return $self->{__connected};
}

=head2 client_config

  print $moo->client_config('location');
  $conf = $moo->client_config();

Reads the moosic clients config. If a $key argument is given it returns only the
value associated with that key, if not the whole config hash.

Would it be a good idea to make the user able to edit the client_config here?
Suggestions or maybe patches are welcome.

=cut

sub client_config {
    my ($self, $key) = @_;
    if($key) {
        return $self->{__client_config}{$key};
    } else {
        return $self->{__client_config};
    }
}

=head2 ping

  die unless $moo->ping;

Checks if we're still connected. This method checks the connection explicitly by
calling the no_op server method. connected() only checks the value of the
'connected' object property.

=cut

sub ping {
    my $self = shift;

    my $resp = $self->{__rpc_xml_client}->send_request('no_op');

    if( ref $resp ) {
        $self->{__connected} = 1;
    } else {
        $self->{__connected} = 0;
    }

    return $self->connected;
}

=head2 error

  my $error = $moo->error;
  $moo->error('Whaaa!');

If an argument is given it adds the error string to the internal error array. If
called in scalar context it returns the last error occured. If you call error()
in list context the whole error array of the Audio::Moosic instance is returned.

=cut

sub error {
    my ($self, $error) = @_;

    if($error) {
        push(@{$self->{__errors}}, $error);
    } else {
        return wantarray ?
            @{$self->{__errors}} :
            @{$self->{__errors}}[@{$self->{__errors}} - 1];
    }
}

=head2 call

  $moo->call('foo');
  $moo->call('bar', RPC::XML::int->new(3));

This method calls a xml-rpc method on the moosic server. The first argument
should be the method name. The arguments of that method should follow behind.

If the request to the moosic server could not be sent the Audio::Moosic instance
disconnects from the server and puts the error message into the internal error
array. Access it via error(). The object won't send any calls anymore if such an
error occured. You should try to reconnect.

If the request could be sent, but returned an error the error message is added
to the error array accessable via error().

If any error occured call() returns undef. If everything went fine the value of
the response is returned.

Normally you don't need to call this method. It is only used by other moosic
methods to send their calls more easily. If a new moosic method is not supported
by this library yet you'll maybe need to use call() manually. Please notice me
if that happens so I'll add the new method.

=cut

sub call {
    my ($self, $method, @args) = @_;
    return unless $self->connected;
    my $resp = $self->{__rpc_xml_client}->send_request($method, @args);

    unless( ref $resp ) {
        my $error = qq/Lost connection to moosic server: "$resp"/;
        if( my $function = (caller(1))[3]) { $error .= " in $function()"; }
        $self->error($error);
        $self->{__connected} = 0;
        return;
    }

    if( $resp->is_fault ) {
        my $error = 'Error: '. $resp->code .': "'. $resp->string .'"';
        if( my $function = (caller(1))[3]) { $error .= " in $function()"; }
        $self->error($error);
        return;
    }

    return $resp->value;
}

=head2 api_version

  @api = $moo->api_version;
  $api = $moo->api_version;

Return the moosic servers API version. If called in scalar context a version
string like '1.3' is returned. In list context the mayor and minor numbers of
the API version are returned.

=cut

sub api_version {
    my $self = shift;
    my $resp = $self->call('api_version') or return;
    return wantarray ? @{$resp} : join('.', @{$resp});
}

=head2 append

  $moo->append('/home/florian/whatever.ogg');
  $moo->append('/home/florian/foo.ogg', '/home/florian/bar.mp3');

Add songs to the moosic queue. The files to add should be the arguments for the
append method. append() returns 1 if there were no errors or something false if
there were some.

=cut

sub append {
    my ($self, @items) = @_;
    return $self->call('append', RPC::XML::array->new(
                map { RPC::XML::base64->new($_) } @items
    ));
}

=head2 clear

  $moo->clear;

Clears the moosic queue. Only the current song remains playing.

=cut

sub clear {
    my $self = shift;
    return $self->call('clear');
}

=head2 crop

  $moo->crop(4);
  $moo->crop(3, 4);

Remove all playlist items that don't fall within a given range. If the range is
represented by one integer all items whose index is greater than or equal to the
value will be removed. Two intergers represent all items whose index is greater
than or equal to the value of first integer and less than the value of the
second integer.

=cut

sub crop {
    my ($self, @range) = @_;
    return $self->call('crop', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 crop_list

  $moo->crop_list(1, 4, 3);

Remove all queued items exept those referenced by a list of positions.

=cut

sub crop_list {
    my ($self, @range) = @_;
    return $self->call('crop_list', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 current

  print $moo->current;

Return the name of the current playing song.

=cut

sub current {
    my $self = shift;
    return $self->call('current');
}

=head2 current_time

  print $moo->current_time;

Return the amount of time the current song has been playing.

=cut

sub current_time {
    my $self = shift;
    return $self->call('current_time');
}

=head2 cut

  $moo->cut(3);
  $moo->cut(4, 10);

Remove all queued items that fall within a given range. See crop() for details
on how that range should look like.

=cut

sub cut {
    my ($self, @range) = @_;
    return $self->call('cut', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 cut_list

  $moo->cut_list(3, 7, 9);

Remove all queued items referenced by list of positions.

=cut

sub cut_list {
    my ($self, @range) = @_;
    return $self->call('cut_list', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 die

  $moo->die;

Tell the server to terminate itself.

=cut

sub die {
    my $self = shift;
    ($self->call('die') and $self->disconnect) or return;
}

=head2 filter

  $moo->filter('foo');
  $moo->filter('bar', 4);
  $moo->filter('moo', 7, 11);

Remove all items that don't match the given regular expression. You may limit
this operation to a specific range which is described in crop().

=cut

sub filter {
    my ($self, $regex, @range) = @_;
    return $self->call('filter',
            RPC::XML::base64->new($regex),
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range )
    );
}

=head2 get_history_limit

  $limit = $moo->get_history_limit;

Get the limit on the size of the history list stored in servers memory.

=cut

sub get_history_limit {
    my $self = shift;
    return $self->call('get_history_limit');
}

=head2 getconfig

  @config = $moo->getconfig;

Return a list of the server's filetype-player associations.

=cut

sub getconfig {
    my ($self, $key) = @_;
    my $resp = $self->call('getconfig');
    return @{$resp};
    #TODO support $key to read single config options
}

=head2 halt_queue

  $moo->halt_queue;

Stop any new songs from being played. Use run_queue() to reverse this state.

=cut

sub halt_queue {
    my $self = shift;
    return $self->call('halt_queue');
}

=head2 haltqueue

See halt_queue().

=cut

sub haltqueue {
    my $self = shift;
    $self->halt_queue;
}

=head2 history

  %hist = $moo->history;

Return a list of items that has been recently played. If a positive integer
argument is given than no more than number of items will be returned. Otherwise
the entire history is printed.

history() returns an array of hashrefs like that:
  @history = (
    { title => 'foo', start => 123.45, stop => 543.21 },
    { title => 'bar', start => 234.56, stop => 654.32 },
    ...
  );

=cut

sub history {
    my ($self, $num) = @_;

    return map {
        title    => $_->[0],
        start    => $_->[1],
        stop    => $_->[2] }, @{$self->call('history',
                RPC::XML::int->new( $num || 0 )) };
}

=head2 indexed_list

  %list = $moo->indexed_list;
  %list = $moo->indexed_list(1);
  %list = $moo->indexed_list(2, 5);

List the song queue's contents. If a range is specified, only the items that
fall within that range are listed.

indexed_list() returns a hash like that:
  %list = (
    list => [ 'foo', 'bar', 'moo', ... ],
    start => 4
  );

=cut

sub indexed_list {
    my ($self, @range) = @_;

    return $self->call('indexed_list', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 insert

  $moo->insert(4, 'foo.ogg', 'bar.mp3');

Insert items at a given position in the queue.

=cut

sub insert {
    my $self = shift;
    my $num = pop;
    my @items = @_;

    return $self->call('insert',
            RPC::XML::array->new( map { RPC::XML::base64->new($_) } @items ),
            RPC::XML::int->new( $num )
    );
}

=head2 is_looping

  $moo->toggle_loop_mode if $moo->is_looping;

Check whether the loop mode is on or not.

=cut

sub is_looping {
    my $self = shift;
    return $self->call('is_looping');
}

=head2 is_paused

  $moo->toggle_pause if $moo->is_paused;

Check whether the current song is paused or not.

=cut

sub is_paused {
    my $self = shift;
    return $self->call('is_paused');
}

=head2 is_queue_running

  if($moo->is_queue_running) {
    ...;
  }

Check whether the queue consumption (advancement) is activated.

=cut

sub is_queue_running {
    my $self = shift;
    return $self->call('is_queue_running');
}

=head2 last_queue_update

  $time = $moo->last_queue_update

Return the time at which the song queue was last modified.

=cut

sub last_queue_update {
    my $self = shift;
    return $self->call('last_queue_update');
}

=head2 length

  $length = $moo->length

Return the number of items in the song queue.

=cut

sub length {
    my $self = shift;
    return $self->call('length');
}

=head2 list

  @list = $moo->list();
  @list = $moo->list(2);
  @list = $moo->list(4, 8);
  $list_ref = $moo->list()

List the song queue's contents. If a range is specified, only the items that
fall within that range are listed. Returns an array if called in list context
or an array reference if it's called in scalar context.

=cut

sub list {
    my ($self, @range) = @_;

    my $list = $self->call('list', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));

    return wantarray ?
        @{$list} :
        $list;
}

=head2 move

  $moo->move(10, 4);
  $moo->move(4, 7, 1);

Move a range of items to a new position within the queue.

=cut

sub move {
    my $self = shift;
    my $num = pop;
    my @range = @_;

    return $self->call('move',
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range ),
            RPC::XML::int->new( $num )
    );
}

=head2 move_list

  $moo->move(3, 5, 7, 11);

Move the items referenced by a list of positions to a new position.

=cut

sub move_list {
    my $self = shift;
    my $num = pop;
    my @range = @_;

    return $self->call('move_list',
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range ),
            RPC::XML::int->new( $num )
    );
}

=head2 next

  $moo->next;
  $moo->next(5);

Stop the current song (if any), and jumps ahead to a song that is currently in
the queue. The skipped songs are recorded in the history as if they had been
played. When called without arguments, this behaves very much like the skip()
method, except that it will have an effect even if nothing is currently playing.

=cut

sub next {
    my ($self, $num) = @_;

    return $self->call('next', RPC::XML::int->new( $num || 1 ));
}

=head2 no_op

  $moo->no_op

Do nothing, successfully.

=cut

sub no_op {
    my $self = shift;
    return $self->call('no_op');
}

=head2 pause

  $moo->pause;

Pause the currently playing song.

=cut

sub pause {
    my $self = shift;
    return $self->call('pause');
}

=head2 prepend

  $moo->prepend('foo.ogg', 'bar.mp3');

Add items to the beginning of the queue.

=cut

sub prepend {
    my ($self, @items) = @_;

    return $self->call('prepend', RPC::XML::array->new(
                map { RPC::XML::base64->new($_) } @items
    ));
}

=head2 previous

  $moo->previous;
  $moo->previous(3);

Stops the current song (if any), removes the most recently played song from the
history, and puts these songs at the head of the queue. When loop mode is on,
the songs at the tail of the song queue are used instead of the most recently
played songs in the history.

=cut

sub previous {
    my ($self, $num) = @_;

    return $self->call('previous', RPC::XML::int->new( $num || 1 ));
}

=head2 putback

  $moo->putback;

Place the currently playing song at the beginning of the queue.

=cut

sub putback {
    my $self = shift;
    return $self->call('putback');
}

=head2 queue_length

  $length = $moo->queue_length;

Return the number of items in the song queue.

=cut

sub queue_length {
    my $self = shift;
    return $self->call('queue_length');
}

=head2 reconfigure

  $moo->reconfigure;

Tell the server to reread its player configuration file.

=cut

sub reconfigure {
    my $self = shift;
    return $self->call('reconfigure');
}

=head2 remove

  $moo->remove('regex');
  $moo->remove('regex', 4);
  $moo->remove('regex', 1, 3);

Remove all items that match the given regular expression. You can limit this
operation by giving a range as described in crop() as last argument.

=cut

sub remove {
    my ($self, $regex, @range) = @_;

    return $self->call('remove',
            RPC::XML::base64->new( $regex ),
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range )
    );
}

=head2 replace

  $moo->replace('foo.ogg', 'bar.mp3');

Replace the contents of the queue with the given items. This is equivalent to
calling clear() and prepend() in succession, except that this operation is
atomic.

=cut

sub replace {
    my ($self, @items) = @_;

    return $self->call('replace', RPC::XML::array->new(
                map { RPC::XML::base64->new($_) } @items
    ));
}

=head2 reverse

  $moo->reverse;
  $moo->reverse(2);
  $moo->reverse(5, 7);

Reverse the order of the items in the queue. You can limit this operation by
giving a range as described in crop() as last argument.

=cut

sub reverse {
    my ($self, @range) = @_;

    return $self->call('reverse', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 run_queue

  $moo->run_queue;

Allows new songs to be played again after halt_queue() has been called.

=cut

sub run_queue {
    my $self = shift;
    return $self->call('run_queue');
}

=head2 runqueue

See run_queue().

=cut

sub runqueue {
    my $self = shift;
    return $self->run_queue;
}

=head2 set_history_limit

  $moo->set_history_limit(44);

Set the limit on the size of the history list stored in memory.

=cut

sub set_history_limit {
    my ($self, $limit) = @_;

    return $self->call('set_history_limit', RPC::XML::int->new( $limit ));
}

=head2 set_loop_mode

  $moo->set_loop_mode(0);
  $moo->set_loop_mode(1);

Turn loop mode on or off.

=cut

sub set_loop_mode {
    my ($self, $mode) = @_;

    return $self->call('set_loop_mode', RPC::XML::boolean->new( $mode ));
}

=head2 showconfig

  my $config = $moo->showconfig;
  my %config = $moo->showconfig;

Return the server's player configuration. If showconfig() is called in scalar
context a scalar containing the textual description of the configuration is
returned. If you call showconfig() in list context a hash which maps the
configuration regular expression to the player commands is returned.

=cut

sub showconfig {
    my $self = shift;

    my $config = $self->call('showconfig');
    return unless $config;
    return $config unless wantarray;

    my @config;
    foreach(split("\n", $config)) {
        s/^\s+//;
        chomp;
        push(@config, $_);
    }

    return @config;
}

=head2 shuffle

  $moo->shuffle;
  $moo->shuffle(2);
  $moo->shuffle(4, 6);

Rearrange the contents of the queue into a random order. You can limit this
operation by giving a range as described for crop() as last argument.

=cut

sub shuffle {
    my ($self, @range) = @_;

    return $self->call('shuffle', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 skip

  $moo->skip;

Skips the rest of the current song to play the next song in the queue. This only
has an effect if there actually is a current song.

=cut

sub skip {
    my $self = shift;
    return $self->call('skip');
}

=head2 sort

  $moo->sort;
  $moo->sort(2);
  $moo->sort(4, 6);

Arrange the contents of the queue into sorted order.

=cut

sub sort {
    my ($self, @range) = @_;

    return $self->call('sort', RPC::XML::array->new(
                map { RPC::XML::int->new($_) } @range
    ));
}

=head2 stop

  $moo->stop;

Stop playing the current song and stops new songs from playing. The current
song is returned to the head of the song queue and is not recorded in the
history list. If loop mode is on, the current song won't be placed at the end of
the song queue when it is stopped.

=cut

sub stop {
    my $self = shift;
    return $self->call('stop');
}

=head2 sub

  $moo->sub('regex', 'substitition');
  $moo->sub('regex', 'substitition', 2);
  $moo->sub('regex', 'substitition', 1, 7);

Perform a regular expression substitution on the items in the queue. You can
limit this operation by giving a range as described for crop() as last argument.

=cut

sub sub {
    my ($self, $regex, $subst, @range) = @_;

    return $self->call('sub',
            RPC::XML::base64->new( $regex ),
            RPC::XML::base64->new( $subst ),
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range )
    );
}

=head2 sub_all

  $moo->sub_all('regex', 'substition');
  $moo->sub_all('regex', 'substition', 2);
  $moo->sub_all('regex', 'substition', 1, 7);

Performs a global regular expression substitution on the items in the queue.

=cut

sub sub_all {
    my ($self, $regex, $subst, @range) = @_;

    return $self->call('sub_all',
            RPC::XML::base64->new( $regex ),
            RPC::XML::base64->new( $subst ),
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @range )
    );
}

=head2 swap

  $moo->swap( [7, 10], [ 5 ]  );

Swap the items contained in one range with the items contained in the other
range. The ranges for the swap() method needs to be passed as array references
in contrast to other methods that use ranges.

=cut

sub swap {
    my ($self, $range1, $range2) = @_;

    return $self->call('swap',
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @{$range1} ),
            RPC::XML::array->new( map { RPC::XML::int->new($_) } @{$range2} )
    );
}

=head2 listMethods

  @methods = $moo->listMethods;

Return an array of all available XML-RPC methods on this server.

=cut

sub listMethods {
    my $self = shift;
    return $self->call('system.listMethods');
}

=head2 methodHelp

  $help = $moo->methodHelp('sub');

Given the name of a method, return a help string.

=cut

sub methodHelp {
    my ($self, $method) = @_;

    return $self->call('syste.methodHelp',
            RPC::XML::string->new( $method )
    );
}

=head2 methodSignature

  $signature = $moo->methodSignature;

Given the name of a method, return an array of legal signatures. Each signature
is an array of scalars. The first item of each signature is the return type, and
any others items are parameter types.  =cut

=cut

sub methodSignature {
    my ($self, $method) = @_;

    return $self->call('system.methodSignature',
            RPC::XML::string->new( $method )
    );
}

=head2 multicall

  $moo->multicall(...);

Process an array of calls, and return an array of results. This is not
implemented yet.

=cut

sub multicall {
    my ($self, @cmds) = @_;
    require Carp;
    Carp::carp(__PACKAGE__."::multicall() isn't implemented yet."); #TODO
}

=head2 toggle_loop_mode

  $moo->toggle_loop_mode;

Turn loop mode on if it is off, and turns it off if it is on.

=cut

sub toggle_loop_mode {
    my $self = shift;
    return $self->call('toggle_loop_mode');
}

=head2 toggle_pause

  $moo->toggle_pause;

Pause the current song if it is playing, and unpauses if it is paused.

=cut

sub toggle_pause {
    my $self = shift;
    return $self->call('toggle_pause');
}

=head2 unpause

  $moo->unpause;

Unpauses the current song.

=cut

sub unpause {
    my $self = shift;
    return $self->call('unpause');
}

=head2 version

  $version = $moo->version;

Return the Moosic server's version string.

=cut

sub version {
    my $self = shift;
    return $self->call('version');
}

=head1 HELPER METHODS

The following methods aren't methods defined by the moosic API but should be
usefull when dealing with a moosic server.

=head2 play

  $moo->play();

Start playing. If the playback is paused it will be unpaused. If the queue is
stopped it will be started.

=cut

sub play {
    my $self = shift;

    return $self->unpause() if $self->is_paused();
    return $self->run_queue();
}

=head2 can_play

  $moo->append( $song ) if $moo->can_play( $song );

Takes a list of songs as argument and returns all items that can be played by
the moosic daemon.

=cut

sub can_play {
    my $self = shift;
    my @can_play;

    my @config = $self->getconfig();
    for my $track ( @_ ) {
        for( @config ) {
            push @can_play, $track if $track =~ qr/$_->[0]/;
        }
    }

    return @can_play;
}

package Audio::Moosic::Inet;

use strict;
use warnings;
use base qw( Audio::Moosic );

sub connect {
    my ($self, $host, $port) = @_;
    return if $self->connected;

    my $location = "http://$host\:$port";
    $self->disconnect;
    $self->{__rpc_xml_client} =    RPC::XML::Client->new($location);

    $self->ping or return;
    $self->{__client_config} = { location => $location };
}

package Audio::Moosic::Unix;

use strict;
use warnings;
use base qw( Audio::Moosic );


sub connect {
    _init();

    my ($self, $filename) = @_;
    return if $self->connected;

    $filename = ($ENV{HOME} || '/tmp') . '/.moosic/socket' unless $filename;
    my $location  = "http://$filename";
    $self->disconnect;
    $self->{__rpc_xml_client} = RPC::XML::Client->new($location);

    $self->ping or return;
    $self->{__client_config} = { location => $location };
}

sub _init {

    unless( eval 'require LWP::Protocol::http::SocketUnix' ) {
        require Carp;
        Carp::croak('You need LWP::Protocol::http::SocketUnix to connect to a local'.
                " moosic server using a UNIX socket.\nPlease install it!");
    }

    LWP::Protocol::implementor( http => 'LWP::Protocol::http::SocketUnix' );
}

1;

=head1 BUGS

=over 4

=item * check arguments more strictly

expecially for constructors.

=back

If you find some others please report them to Florian Ragwitz
E<lt>flora@cpan.orgE<gt>

=head1 TODO

=over 4

=item * implement system_multicall

=item * improve client_config

=item * maybe use autoloader to load subs on demand

create the method arguments from methodSignature.

=back

=head1 SEE ALSO

moosic(1), moosicd(1), http://nanoo.org/~daniel/moosic/

=head1 AUTHOR

Florian Ragwitz E<lt>rafl@debian.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2004-2008 by Florian Ragwitz

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.4 or,
at your option, any later version of Perl 5 you may have available.

=cut