script/ircindexer-single

filter: Statementstmt 69.6% 39 / 56 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 71.6% 53 / 74 CC 3 SCAR 9.3
CC
3
Cov
66%
__ANON__
8.2
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« lib/IRC/Indexer/Logger.pm ↑ Summary lib/IRC/Indexer/Output/Dumper.pm »
1 #!/usr/local/bin/perl
2  
3 ## Example single-server trawler using postback.
4  
5 2 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use IRC::Indexer::Trawl::Bot;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use IRC::Indexer::Output::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use IRC::Indexer::Output::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use IRC::Indexer::Output::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my($server, $port, $verbose, $outpath, $timeout, $interval);
17 2 my $fmt = 'STDOUT';
18  
19 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 GetOptions(
21 1 ▶ 'help' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
22 1 print(
23 "ircindexer-single help\n\n",
24
25 " -s, --server=SERVER\n",
26 " Destination server.\n\n",
27
28 " -p, --port=PORT\n",
29 " Destination port [6667]\n\n",
30
31 " -f, --format=FORMAT\n",
32 " One of: JSON, YAML, Dumper\n\n",
33
34 " -t, --timeout=SECS\n",
35 " IRC session timeout in seconds.\n\n",
36
37 " -i, --interval=SECS\n",
38 " Interval between IRC requests in seconds.\n\n",
39
40 " -o, --output=PATH\n",
41 " File to write output to (rather than STDOUT)\n",
42 );
43
44 1 exit 0
45 },
46
47 2 'verbose:0' => \$verbose,
48  
49 'server=s' => \$server,
50 'port:6667' => \$port,
51
52 'timeout:90' => \$timeout,
53 'interval:15' => \$interval,
54
55 'format|export=s' => \$fmt,
56
57 'output=s' => \$outpath,
58 );
59  
60 1 ▶die "Missing --server\n" unless $server;
Branch: 1 branch
BranchTrueFalseTotal
unless $server 0 1 1
61  
62 1 warn "Connecting to: $server\n";
63  
64 POE::Session->create(
65 inline_states => {
66 1 ▶ '_start' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 1 IRC::Indexer::Trawl::Bot->spawn(
68 postback => $_[SESSION]->postback('trawler_done'),
69 server => $server,
70 port => $port,
71 verbose => $verbose,
72 timeout => $timeout,
73 interval => $interval,
74 );
75 },
76
77 1 ▶ trawler_done => sub {
Subroutine __ANON__: called CC=3 SCAR=21.1
78 ## Should have gotten the trawler obj.
79 ## ARG1 will be an arrayref.
80 1 my $trawl = $_[ARG1]->[0];
81 1 ▶ if ($trawl->failed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trawl->failed) 1 0 1
82 1 die "Trawler failed: ".$trawl->failed
83 }
84
85 0 my $info = $trawl->info;
86 0 $info->channels; ## builds sorted chan list
87 0 my $ref = $trawl->dump;
88 0 undef $trawl;
89 0 warn "Done\n";
90  
91 0 my $output;
92 0 given ($fmt) {
93 0 when ("JSON") {
94 0 $output = IRC::Indexer::Output::JSON->new(
95 Input => $ref,
96 );
97 }
98
99 0 when ("YAML") {
100 0 $output = IRC::Indexer::Output::YAML->new(
101 Input => $ref,
102 );
103 }
104
105 0 default {
106 0 $output = IRC::Indexer::Output::Dumper->new(
107 Input => $ref,
108 );
109 }
110 }
111
112 0 ▶ if ($outpath) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outpath) { } 0 0 0
113 0 warn "Writing: $outpath\n";
114 0 $output->write($outpath);
115 } else {
116 0 print $output->dump;
117 }
118  
119 },
120
121 }, ## inline_states
122 1 );
123  
124 1 POE::Kernel->run;
125  
126 __END__
« lib/IRC/Indexer/Logger.pm ↑ Summary lib/IRC/Indexer/Output/Dumper.pm »