bin/derived

filter: Statementstmt 100% 51 / 51 Branchbran 54.5% 12 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 87.8% 72 / 82 CC 4 SCAR 7.0
CC
4
Cov
86%
load_derviedfile
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« lib/App/derived/Plugin.pm ↑ Summary lib/App/derived/Plugin/Dumper.pm »
1 #!/usr/bin/perl
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use App::derived;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Getopt::Long qw/:config posix_default no_ignore_case bundling/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Pod::Usage qw/pod2usage/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶ use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 8 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("h|help", \my $help, "i=i", \my $interval, "M=s\@", \my @plugins, "port=i", \my $port, "host=i", \my $host) or pod2usage(1) 8 0 8
13 'h|help' => \my $help,
14 'i=i' => \my $interval,
15 'M=s@' => \my @plugins,
16 'port=i' => \my $port,
17 'host=i' => \my $host,
18 ) or pod2usage(1);
19  
20 8 ▶pod2usage(-verbose=>2,-exitval=>0) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 8 8
21 8 my ($derivedfile) = @ARGV;
22 8 ▶pod2usage(-verbose=>1,-exitval=>1) unless $derivedfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $derivedfile 0 8 8
23  
24 8 ▶$interval = 10 unless $interval;
Branch: 1 branch
BranchTrueFalseTotal
unless $interval 0 8 8
25 8 ▶$port = 12306 unless $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $port 8 0 8
26 8 ▶$host = '0' unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 8 0 8
27  
28 8 ▶push @plugins, 'Memcached' if @plugins == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @plugins == 0 0 8 8
29  
30 8 my $derived = App::derived->new(
31 interval => $interval,
32 );
33 8 my $services = load_derviedfile($derivedfile);
34  
35 8 for my $service ( keys %$services ) {
36 16 $derived->add_service($service, $services->{$service});
37 }
38  
39 8 foreach my $plugin ( @plugins ) {
40 8 my ($plugin, @args) = split /,/, $plugin;
41 8 my %args = map { split /=/, $_ } @args;
42
43 8 ▶ $plugin = "App::derived::Plugin::" . $plugin if $plugin !~ m!^\+!;
Branch: 1 branch
BranchTrueFalseTotal
unless $plugin =~ /^\+/ 8 0 8
44 8 load($plugin);
45 8 $derived->add_plugin( $plugin, {
46 host => $host,
47 port => $port,
48 %args
49 });
50 }
51  
52 8 $derived->run;
53  
54 8 ▶sub load_derviedfile {
Subroutine load_derviedfile: called CC=4 SCAR=14.0
55 8 my $file = shift;
56 8 my %services;
57 8 ▶ open(my $fh, '<:utf8', $file) or die "cannot load file $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:utf8", $file or die "cannot load file ${file}: $!" 8 0 8
58 8 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 16 8 24
59 16 ▶ if (my ($name, $command) = ($line =~ /^([^:]+)\s*:\s*(.+)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ /^([^:]+)\s*:\s*(.+)/) 16 0 16
60 16 $services{$name} = $command;
61 }
62 }
63 8 return \%services;
64 }
65  
66 __END__
« lib/App/derived/Plugin.pm ↑ Summary lib/App/derived/Plugin/Dumper.pm »