« blib/lib/POE/Component/Client/MPD/Collection.pm
↑ Summary
blib/lib/POE/Component/Client/MPD/Message.pm »
| 1 | # | ||||||||||||||
| 2 | # This file is part of POE-Component-Client-MPD | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # This software is copyright (c) 2007 by Jerome Quelin. | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 8 | # | ||||||||||||||
| 9 | 14 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 14 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 14 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | package POE::Component::Client::MPD::Test; | ||||||||||||||
| 14 | # ABSTRACT: automate pococ-mpd testing | ||||||||||||||
| 15 | 11 | $POE::Component::Client::MPD::Test::VERSION = '2.000'; | |||||||||||||
| 16 | 14 | ▶ | use Moose 0.92; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 14 | ▶ | use MooseX::Has::Sugar; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 14 | ▶ | use MooseX::POE; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 14 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 14 | ▶ | use MooseX::Types::Moose qw{ ArrayRef Str }; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 14 | ▶ | use POE; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 14 | ▶ | use Readonly; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 11 | Readonly my $K => $poe_kernel; | |||||||||||||
| 25 | |||||||||||||||
| 26 | |||||||||||||||
| 27 | 11 | has alias => ( ro, isa=>Str, default=>'tester' ); | |||||||||||||
| 28 | 11 | has tests => ( | |||||||||||||
| 29 | ro, auto_deref, required, | ||||||||||||||
| 30 | isa => ArrayRef, | ||||||||||||||
| 31 | traits => [ 'Array' ], | ||||||||||||||
| 32 | handles => { | ||||||||||||||
| 33 | peek => [ get => 0 ], | ||||||||||||||
| 34 | pop_test => 'shift', | ||||||||||||||
| 35 | nbtests => 'count', | ||||||||||||||
| 36 | }, | ||||||||||||||
| 37 | ); | ||||||||||||||
| 38 | |||||||||||||||
| 39 | |||||||||||||||
| 40 | # -- builders & initializer | ||||||||||||||
| 41 | |||||||||||||||
| 42 | # | ||||||||||||||
| 43 | # START() | ||||||||||||||
| 44 | # | ||||||||||||||
| 45 | # called as poe session initialization | ||||||||||||||
| 46 | # | ||||||||||||||
| 47 | sub START { | ||||||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
START: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 49 | 0 | $K->alias_set($self->alias); # refcount++ | |||||||||||||
| 50 | 0 | $K->yield( 'next_test' ); # launch the first test. | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | |||||||||||||||
| 54 | # -- public events | ||||||||||||||
| 55 | |||||||||||||||
| 56 | |||||||||||||||
| 57 | event next_test => sub { | ||||||||||||||
| 58 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.3
Subroutine
next_test: not called CC=2 SCAR=14.3
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | ▶ | if ( $self->nbtests == 0 ) { # no more tests. | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 61 | 0 | $K->alias_remove( $self->alias ); | |||||||||||||
| 62 | 0 | $K->post('mpd', 'disconnect'); | |||||||||||||
| 63 | 0 | return; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | # post next event. | ||||||||||||||
| 67 | 0 | my $test = $self->peek; | |||||||||||||
| 68 | 0 | my $event = $test->[0]; | |||||||||||||
| 69 | 0 | my $args = $test->[1]; | |||||||||||||
| 70 | 0 | $K->post( 'mpd', $event, @$args ); | |||||||||||||
| 71 | 11 | }; | |||||||||||||
| 72 | |||||||||||||||
| 73 | |||||||||||||||
| 74 | |||||||||||||||
| 75 | event mpd_result => sub { | ||||||||||||||
| 76 | 0 | ▶ | my ($self, $msg, $results) = @_[OBJECT, ARG0, ARG1]; | ||||||||||||
|
Subroutine
mpd_result: not called CC=1 SCAR=2.2
| |||||||||||||||
| 77 | 0 | my $test = $self->peek; | |||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | $test->[3]->($msg, $results); # check if everything went fine | |||||||||||||
| 80 | 0 | $K->delay_set( next_test => $test->[2] ); # call next test after some time | |||||||||||||
| 81 | 0 | $self->pop_test; # remove test being played | |||||||||||||
| 82 | 11 | }; | |||||||||||||
| 83 | |||||||||||||||
| 84 | |||||||||||||||
| 85 | 11 | 1; | |||||||||||||
| 86 | |||||||||||||||
| 87 | __END__ | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =pod | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =head1 NAME | ||||||||||||||
| 92 | |||||||||||||||
| 93 | POE::Component::Client::MPD::Test - automate pococ-mpd testing | ||||||||||||||
| 94 | |||||||||||||||
| 95 | =head1 VERSION | ||||||||||||||
| 96 | |||||||||||||||
| 97 | version 2.000 | ||||||||||||||
| 98 | |||||||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||||||
| 100 | |||||||||||||||
| 101 | POE::Component::Client::MPD->spawn( ... ); | ||||||||||||||
| 102 | POE::Component::Client::MPD::Test->new( { tests => [ | ||||||||||||||
| 103 | [ 'event', [ $arg1, $arg2, ... ], $sleep, \&check_results ], | ||||||||||||||
| 104 | ... | ||||||||||||||
| 105 | ] } ); | ||||||||||||||
| 106 | POE::Kernel->run; | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =head1 DESCRIPTION | ||||||||||||||
| 109 | |||||||||||||||
| 110 | This module implements a L<POE::Session> used to schedule tests | ||||||||||||||
| 111 | according to a plan, calling hooks used to check whether a given test | ||||||||||||||
| 112 | was successful. | ||||||||||||||
| 113 | |||||||||||||||
| 114 | To use it, you need to first spawn a L<POE::Component::Client::MPD> | ||||||||||||||
| 115 | session - it's this session that will be tested. And don't forget to | ||||||||||||||
| 116 | call L<POE>'s mainloop! | ||||||||||||||
| 117 | |||||||||||||||
| 118 | Once started, it will fire the first event to the | ||||||||||||||
| 119 | L<MPD|POE::Component::Client::MPD> session, wait for the return message, | ||||||||||||||
| 120 | call the check callback, and wait a bit... before starting again with | ||||||||||||||
| 121 | the next event in the list. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | When all events have been sent, the session will shut down itself. | ||||||||||||||
| 124 | |||||||||||||||
| 125 | =head1 ATTRIBUTES | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =head2 alias | ||||||||||||||
| 128 | |||||||||||||||
| 129 | The session alias. Defaults to C<tester>. | ||||||||||||||
| 130 | |||||||||||||||
| 131 | =head2 tests | ||||||||||||||
| 132 | |||||||||||||||
| 133 | The list (array ref) of tests to run. It is required in the constructor | ||||||||||||||
| 134 | call. Each list item is an array reference with the following sub-items: | ||||||||||||||
| 135 | |||||||||||||||
| 136 | =over 4 | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =item * event - the event to send to the | ||||||||||||||
| 139 | L<POE::Component::Client::MPD> session | ||||||||||||||
| 140 | |||||||||||||||
| 141 | =item * args - event arguments (an array reference) | ||||||||||||||
| 142 | |||||||||||||||
| 143 | =item * sleep - number of seconds to wait before calling next events | ||||||||||||||
| 144 | |||||||||||||||
| 145 | =item * callback - a sub reference to check the results of current | ||||||||||||||
| 146 | event. The real tests should be done in this sub. It will be called with | ||||||||||||||
| 147 | the message received and the message payload. | ||||||||||||||
| 148 | |||||||||||||||
| 149 | =back | ||||||||||||||
| 150 | |||||||||||||||
| 151 | =head1 PUBLIC EVENTS ACCEPTED | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =head2 next_test( ) | ||||||||||||||
| 154 | |||||||||||||||
| 155 | Called to schedule the next test. | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =head2 mpd_result( $msg ) | ||||||||||||||
| 158 | |||||||||||||||
| 159 | Called when mpd talks back, with C<$msg> as a | ||||||||||||||
| 160 | L<POE::Component::Client::MPD::Message> param. | ||||||||||||||
| 161 | |||||||||||||||
| 162 | =for Pod::Coverage::TrustPod START | ||||||||||||||
| 163 | |||||||||||||||
| 164 | =head1 AUTHOR | ||||||||||||||
| 165 | |||||||||||||||
| 166 | Jerome Quelin | ||||||||||||||
| 167 | |||||||||||||||
| 168 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 169 | |||||||||||||||
| 170 | This software is copyright (c) 2007 by Jerome Quelin. | ||||||||||||||
| 171 | |||||||||||||||
| 172 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 173 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 174 | |||||||||||||||
| 175 | =cut | ||||||||||||||