blib/lib/POE/Filter/Slim/CLI.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 96.7% 60 / 62 CC 6 SCAR 8.7
CC
6
Cov
96%
put
4.0
get_one
3.0
BEGIN
1.0
CRAP 2.4
↑ Summary
1 package POE::Filter::Slim::CLI;
2  
3 #
4 # $Id: CLI.pm 26 2007-09-07 04:32:54Z andy $
5 #
6 # Filter lines according to SlimServer's CLI spec:
7 # Any combination of CR, LF, and \0 is accepted, and
8 # the same line-ending must be used for the response
9 #
10 # This filter also splits and unescapes any CLI commands
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use base 'POE::Filter::Line';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub DEBUG () { 0 }
20  
21 sub FRAMING_BUFFER () { 0 }
22 sub INPUT_REGEXP () { 1 }
23 sub OUTPUT_LITERAL () { 2 }
24  
25 1 if ( DEBUG ) {
26 require Data::Dump;
27 }
28  
29 1 our $VERSION = '0.02';
30  
31 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
32 1 my $type = shift;
33
34 1 my $input_regexp = qr/[\x0D|\x0A|\x00]+/;
35
36 1 my $self = $type->SUPER::new(
37 InputRegexp => $input_regexp,
38 );
39
40 1 return $self;
41 }
42  
43 8 ▶sub get_one {
Subroutine get_one: called CC=3 SCAR=11.0
Pod documented
44 8 my $self = shift;
45
46 LINE:
47 8 while (1) {
48 last LINE
49 8 ▶ unless $self->[FRAMING_BUFFER] =~ s/^(.*?)($self->[INPUT_REGEXP])//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[0] =~ s/^(.*?)($self->[1])//s 2 6 8
50
51 6 DEBUG && warn "using line ending: << ", unpack('H*', $2), " >>\n";
52
53 # Save line-ending used in the request, it will be sent in the response
54 6 $self->[OUTPUT_LITERAL] = $2;
55
56 # Split and unescape CLI command
57 6 my @elements = split / /, $1;
58 6 s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for @elements;
59
60 6 return [ \@elements ];
61 }
62
63 2 return [];
64 }
65  
66 2 ▶sub put {
Subroutine put: called CC=4 SCAR=13.9
Pod documented
67 2 my ( $self, $lines ) = @_;
68
69 2 $lines = clone($lines);
70
71 2 my @raw;
72 2 foreach my $line ( @{$lines} ) {
73 4 ▶ if ( ref $line eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $line eq 'ARRAY') { } 4 0 4
74 # Send an array of CLI commands
75 4 my @output;
76 4 for my $item ( @{$line} ) {
77 7 $item = uri_escape($item);
78 7 push @output, $item;
79 }
80 4 push @raw, join( ' ', @output ) . $self->[OUTPUT_LITERAL];
81 }
82 else {
83 0 push @raw, $line . $self->[OUTPUT_LITERAL];
84 }
85 }
86
87 2 DEBUG && warn "CLI Filter sent: " . Data::Dump::dump(\@raw) . "\n";
88
89 2 return \@raw;
90 }
91  
92 1 1;
93 __END__
↑ Summary