File Coverage

blib/lib/AnyEvent/DAAP/Server/Connection.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package AnyEvent::DAAP::Server::Connection;
2 2     2   12 use Any::Moose;
  2         5  
  2         11  
3 2     2   4329 use AnyEvent;
  2         11970  
  2         107  
4 2     2   2530 use AnyEvent::Handle;
  2         42561  
  2         114  
5 2     2   1211 use Net::DAAP::DMAP qw(dmap_pack);
  0            
  0            
6             use HTTP::Response;
7              
8             has handle => (
9             is => 'rw',
10             isa => 'AnyEvent::Handle',
11             required => 1,
12             lazy_build => 1,
13             );
14              
15             sub _build_handle {
16             my $self = shift;
17             return AnyEvent::Handle->new(
18             fh => $self->fh,
19             on_eof => sub {},
20             on_error => sub { warn "$_[2]" },
21             );
22             }
23              
24             has fh => (
25             is => 'rw',
26             isa => 'FileHandle',
27             );
28              
29             has server => (
30             is => 'rw',
31             isa => 'AnyEvent::DAAP::Server',
32             required => 1,
33             weak_ref => 1,
34             );
35              
36             has pause_cv => (
37             is => 'rw',
38             isa => 'AnyEvent::CondVar',
39             );
40              
41             __PACKAGE__->meta->make_immutable;
42              
43             no Any::Moose;
44              
45             sub respond_dmap {
46             my ($self, $dmap) = @_;
47             my $content = dmap_pack $dmap;
48             $self->respond(
49             200, 'OK', [
50             'Content-Type' => 'application/x-dmap-tagged',
51             'Content-Length' => length($content),
52             ], $content,
53             );
54             }
55              
56             sub respond {
57             my $self = shift;
58             my $response = HTTP::Response->new(@_);
59             $self->handle->push_write('HTTP/1.1 ' . $response->as_string("\r\n"));
60             }
61              
62             sub pause {
63             my ($self, $cb) = @_;
64             return $self->{pause_cv} = AE::cv {
65             $self->{pause_cv} = undef;
66             $cb->();
67             };
68             }
69              
70             1;