| 1 | package Parse::DaemontoolsStatus; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | our $VERSION = '0.02'; | |||||||||
| 5 | |||||||||||
| 6 | 7 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||
| 7 | 7 | my $line = shift; | |||||||||
| 8 | |||||||||||
| 9 | 7 | my ($service, $status, $pid, $seconds, $info); | |||||||||
| 10 | |||||||||||
| 11 | # parse up status line | ||||||||||
| 12 | 7 | $line =~ / | |||||||||
| 13 | ^ | ||||||||||
| 14 | (\S+):\s # $1 service | ||||||||||
| 15 | (\S+)\s # $2 status | ||||||||||
| 16 | \(pid\s(\S+)\)\s # $3 pid | ||||||||||
| 17 | (\S+)\s seconds # $4 seconds | ||||||||||
| 18 | (,?\s?.*) # $5 info | ||||||||||
| 19 | $ | ||||||||||
| 20 | /x; | ||||||||||
| 21 | |||||||||||
| 22 | 7 | ($service, $status, $pid, $seconds, $info) = ($1,$2,$3,$4,$5); | |||||||||
| 23 | 7 | ▶ | $info =~ s/^,\s// if $info; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | return +{ | ||||||||||
| 26 | 7 | ▶ | service => $service, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | status => $status, | ||||||||||
| 28 | pid => $pid, | ||||||||||
| 29 | seconds => $seconds, | ||||||||||
| 30 | info => $info, | ||||||||||
| 31 | } if $service; | ||||||||||
| 32 | |||||||||||
| 33 | # parse down status line | ||||||||||
| 34 | 3 | $line =~ / | |||||||||
| 35 | ^ | ||||||||||
| 36 | (\S+):\s # $1 service | ||||||||||
| 37 | (\S+)\s # $2 status | ||||||||||
| 38 | (\S+)\s seconds # $3 seconds | ||||||||||
| 39 | (,?\s?.*) # $4 info | ||||||||||
| 40 | $ | ||||||||||
| 41 | /x; | ||||||||||
| 42 | |||||||||||
| 43 | 3 | ($service, $status, $pid, $seconds, $info) = ($1,$2,undef,$3,$4); | |||||||||
| 44 | 3 | ▶ | $info =~ s/^,\s// if $info; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | return +{ | ||||||||||
| 47 | 3 | ▶ | service => $service, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | status => $status, | ||||||||||
| 49 | pid => $pid, | ||||||||||
| 50 | seconds => $seconds, | ||||||||||
| 51 | info => $info, | ||||||||||
| 52 | } if $service; | ||||||||||
| 53 | |||||||||||
| 54 | # parse not running status line | ||||||||||
| 55 | 1 | $line =~ / | |||||||||
| 56 | ^ | ||||||||||
| 57 | (\S+):\s # $1 service | ||||||||||
| 58 | (supervise\snot\srunning) # $2 status | ||||||||||
| 59 | $ | ||||||||||
| 60 | /x; | ||||||||||
| 61 | |||||||||||
| 62 | 1 | ($service, $status, $pid, $seconds, $info) = ($1,$2,undef,0,''); | |||||||||
| 63 | |||||||||||
| 64 | return +{ | ||||||||||
| 65 | 1 | ▶ | service => $service, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | status => $status, | ||||||||||
| 67 | pid => $pid, | ||||||||||
| 68 | seconds => $seconds, | ||||||||||
| 69 | info => $info, | ||||||||||
| 70 | } if $service; | ||||||||||
| 71 | |||||||||||
| 72 | 0 | return; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | 1; | |||||||||
| 76 | __END__ | ||||||||||