/usr/share/perl5/POE/Component/Client/MPD/Test.pm is in libpoe-component-client-mpd-perl 1.121670-1.
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 | #
# This file is part of POE-Component-Client-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use 5.010;
use strict;
use warnings;
package POE::Component::Client::MPD::Test;
{
$POE::Component::Client::MPD::Test::VERSION = '1.121670';
}
# ABSTRACT: automate pococ-mpd testing
use Moose 0.92;
use MooseX::Has::Sugar;
use MooseX::POE;
use MooseX::SemiAffordanceAccessor;
use MooseX::Types::Moose qw{ ArrayRef Str };
use POE;
use Readonly;
Readonly my $K => $poe_kernel;
has alias => ( ro, isa=>Str, default=>'tester' );
has tests => (
ro, auto_deref, required,
isa => ArrayRef,
traits => [ 'Array' ],
handles => {
peek => [ get => 0 ],
pop_test => 'shift',
nbtests => 'count',
},
);
# -- builders & initializer
#
# START()
#
# called as poe session initialization
#
sub START {
my $self = shift;
$K->alias_set($self->alias); # refcount++
$K->yield( 'next_test' ); # launch the first test.
}
# -- public events
event next_test => sub {
my $self = shift;
if ( $self->nbtests == 0 ) { # no more tests.
$K->alias_remove( $self->alias );
$K->post('mpd', 'disconnect');
return;
}
# post next event.
my $test = $self->peek;
my $event = $test->[0];
my $args = $test->[1];
$K->post( 'mpd', $event, @$args );
};
event mpd_result => sub {
my ($self, $msg, $results) = @_[OBJECT, ARG0, ARG1];
my $test = $self->peek;
$test->[3]->($msg, $results); # check if everything went fine
$K->delay_set( next_test => $test->[2] ); # call next test after some time
$self->pop_test; # remove test being played
};
1;
=pod
=head1 NAME
POE::Component::Client::MPD::Test - automate pococ-mpd testing
=head1 VERSION
version 1.121670
=head1 SYNOPSIS
POE::Component::Client::MPD->spawn( ... );
POE::Component::Client::MPD::Test->new( { tests => [
[ 'event', [ $arg1, $arg2, ... ], $sleep, \&check_results ],
...
] } );
POE::Kernel->run;
=head1 DESCRIPTION
This module implements a L<POE::Session> used to schedule tests
according to a plan, calling hooks used to check whether a given test
was successful.
To use it, you need to first spawn a L<POE::Component::Client::MPD>
session - it's this session that will be tested. And don't forget to
call L<POE>'s mainloop!
Once started, it will fire the first event to the
L<MPD|POE::Component::Client::MPD> session, wait for the return message,
call the check callback, and wait a bit... before starting again with
the next event in the list.
When all events have been sent, the session will shut down itself.
=head1 ATTRIBUTES
=head2 alias
The session alias. Defaults to C<tester>.
=head2 tests
The list (array ref) of tests to run. It is required in the constructor
call. Each list item is an array reference with the following sub-items:
=over 4
=item * event - the event to send to the
L<POE::Component::Client::MPD> session
=item * args - event arguments (an array reference)
=item * sleep - number of seconds to wait before calling next events
=item * callback - a sub reference to check the results of current
event. The real tests should be done in this sub. It will be called with
the message received and the message payload.
=back
=head1 PUBLIC EVENTS ACCEPTED
=head2 next_test( )
Called to schedule the next test.
=head2 mpd_result( $msg )
Called when mpd talks back, with C<$msg> as a
L<POE::Component::Client::MPD::Message> param.
=for Pod::Coverage::TrustPod START
=head1 AUTHOR
Jerome Quelin
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2007 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
|