| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Inferno::RegMgr::Utils; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # update POD & Changes & README | 
| 8 | 1 |  |  | 1 |  | 3 | use version; our $VERSION = qv('0.1.2'); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # update DEPENDENCIES in POD & Makefile.PL & README | 
| 11 | 1 |  |  | 1 |  | 951 | use Perl6::Export::Attrs; | 
|  | 1 |  |  |  |  | 7262 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub quote :Export { | 
| 15 | 0 |  |  | 0 | 1 | 0 | my ($s) = @_; | 
| 16 | 0 | 0 |  |  |  | 0 | if ($s =~ / \s | ' | \A\z /xms) { | 
| 17 | 0 |  |  |  |  | 0 | $s =~ s/'/''/xmsg; | 
| 18 | 0 |  |  |  |  | 0 | $s = "'$s'"; | 
| 19 |  |  |  |  |  |  | } | 
| 20 | 0 |  |  |  |  | 0 | return $s; | 
| 21 | 1 |  |  | 1 |  | 102 | } | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub unquote :Export { | 
| 24 | 0 |  |  | 0 | 1 | 0 | my ($s) = @_; | 
| 25 | 0 | 0 |  |  |  | 0 | if ($s =~ s/\A'(.*)'\z/$1/xms) { | 
| 26 | 0 |  |  |  |  | 0 | $s =~ s/''/'/xmsg; | 
| 27 |  |  |  |  |  |  | } | 
| 28 | 0 |  |  |  |  | 0 | return $s; | 
| 29 | 1 |  |  | 1 |  | 197 | } | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub attr :Export { | 
| 32 | 0 |  |  | 0 | 1 | 0 | my ($attr) = @_; | 
| 33 | 0 |  |  |  |  | 0 | my @s; | 
| 34 | 0 | 0 |  |  |  | 0 | while (my ($k, $v) = each %{ $attr || {} }) { | 
|  | 0 |  |  |  |  | 0 |  | 
| 35 | 0 |  |  |  |  | 0 | push @s, sprintf '%s %s', quote($k), quote($v); | 
| 36 |  |  |  |  |  |  | } | 
| 37 | 0 |  |  |  |  | 0 | return join q{ }, @s; | 
| 38 | 1 |  |  | 1 |  | 196 | } | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | my $qword = qr{( [^'\s]+ | '[^']*(?:''[^']*)*' )}xms; | 
| 41 |  |  |  |  |  |  | sub parse_svc :Export { | 
| 42 | 0 |  |  | 0 | 1 | 0 | my ($s) = @_; | 
| 43 | 0 | 0 |  |  |  | 0 | return ({}, undef) if $s eq q{}; | 
| 44 | 0 | 0 |  |  |  | 0 | return (undef, 'no \\n at end') if $s !~ /\n\z/xms; | 
| 45 | 0 |  |  |  |  | 0 | my %svc; | 
| 46 | 0 |  |  |  |  | 0 | for my $line (split /\n/xms, $s) { | 
| 47 | 0 |  |  |  |  | 0 | my $errmsg = "can't parse service: $line"; | 
| 48 | 0 | 0 |  |  |  | 0 | return (undef, $errmsg) if $line !~ s/\A$qword//xms; | 
| 49 | 0 |  |  |  |  | 0 | my $name = unquote($1); | 
| 50 | 0 |  |  |  |  | 0 | my %attr; | 
| 51 | 0 |  |  |  |  | 0 | while (length $line) { | 
| 52 | 0 | 0 |  |  |  | 0 | return (undef, $errmsg) if $line !~ s/\s$qword\s$qword//xms; | 
| 53 | 0 |  |  |  |  | 0 | my ($attr, $value) = ($1, $2); | 
| 54 | 0 |  |  |  |  | 0 | $attr{ unquote($attr) } = unquote($value); | 
| 55 |  |  |  |  |  |  | } | 
| 56 | 0 |  |  |  |  | 0 | $svc{$name} = \%attr; | 
| 57 |  |  |  |  |  |  | } | 
| 58 | 0 |  |  |  |  | 0 | return (\%svc, undef); | 
| 59 | 1 |  |  | 1 |  | 447 | } | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | my $STDREF = qr{SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE}xms; | 
| 62 |  |  |  |  |  |  | sub run_callback :Export { ## no critic (RequireArgUnpacking) | 
| 63 | 0 | 0 |  | 0 | 1 |  | croak  'usage: run_callback( CB [, METHOD [, @ARGS]] )'    if @_ < 1; | 
| 64 | 0 |  |  |  |  |  | my ($cb, $method) = (shift, shift); | 
| 65 | 0 | 0 |  |  |  |  | my $cb_type | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | = !ref($cb)                         ? 'CLASS' | 
| 67 |  |  |  |  |  |  | : ref($cb) eq 'CODE'                ? 'CODE' | 
| 68 |  |  |  |  |  |  | : ref($cb) !~ m{\A$STDREF\z}xmso    ? 'OBJECT' | 
| 69 |  |  |  |  |  |  | :                                     undef | 
| 70 |  |  |  |  |  |  | ; | 
| 71 | 0 | 0 | 0 |  |  |  | if ($cb_type eq 'CLASS' || $cb_type eq 'OBJECT') { | 
|  |  | 0 |  |  |  |  |  | 
| 72 | 0 |  |  |  |  |  | $cb->$method(@_); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  | elsif ($cb_type eq 'CODE') { | 
| 75 | 0 |  |  |  |  |  | $cb->(@_); | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | else { | 
| 78 | 0 |  |  |  |  |  | croak qq{run_callback: wrong CB $cb}; | 
| 79 |  |  |  |  |  |  | } | 
| 80 | 0 |  |  |  |  |  | return; | 
| 81 | 1 |  |  | 1 |  | 355 | } | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | 1; # Magic true value required at end of module | 
| 86 |  |  |  |  |  |  | __END__ |