Amethyst.pm

filter: Statementstmt 25.9% 21 / 81 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 10 totaltotal 19.8% 27 / 136 CC 15 SCAR 26.6
CC
15
Cov
20%
handler_think
42.0
handler_add_brain
20.0
handler_connect
12.0
CRAP 14.3
« Amethyst/Brain/Infobot/Module/Exchange.pm ↑ Summary Amethyst/Connection.pm »
1 package Amethyst;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Amethyst::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 $VERSION = '1.00';
11 1 @ISA = qw(Exporter);
12  
13 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
14 0 my $class = shift;
15 0 ▶ my $args = ($#_ == 0) ? { %{ (shift) } } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 0 0 0
16  
17 0 my %states = map { $_ => "handler_$_" } qw(
18 _start _stop _child signal
19 add_connection register_connection connect
20 add_brain think
21 );
22 0 POE::Session->create(
23 package_states => [ $class => \%states ],
24 args => [ $args ],
25 );
26 }
27  
28 0 ▶sub handler__start {
Subroutine handler__start: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my ($kernel, $session, $heap, $args) = @_[KERNEL, SESSION, HEAP, ARG0];
30 0 $heap->{Args} = $args;
31 0 ▶ my $name = $args->{Name} || 'amethyst';
Condition0%0/2
$args->{'Name'} || 'amethyst'
l!l
00
MC/DC0%0/1
$args->{'Name'} || 'amethyst'
$args->{'Name'}
Truth table0%0/2
A
A= $args->{'Name'}
Aresult
11
00
32 0 $kernel->alias_set($name);
33  
34 0 print STDERR "Starting Amethyst '$name'\n";
35  
36 0 $heap->{Connections} = { };
37 0 $heap->{Brains} = { };
38  
39 0 $kernel->sig('INT', 'signal');
40 0 $kernel->sig('TERM', 'signal');
41 }
42  
43 0 ▶sub handler_signal {
Subroutine handler_signal: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
45 0 my $signame = $_[ARG0];
46 0 print STDERR "Exiting on signal $signame\n";
47 0 exit;
48 }
49  
50 0 ▶sub handler__stop {
Subroutine handler__stop: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
52 }
53  
54 0 ▶sub handler__child {
Subroutine handler__child: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
56 }
57  
58 0 ▶sub handler_register_connection {
Subroutine handler_register_connection: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my ($kernel, $session, $sender, $heap, $name) =
60 @_[KERNEL, SESSION, SENDER, HEAP, ARG0];
61 0 ▶ die "No name for connection $sender\n" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
62 0 $heap->{Connections}->{$name} = $sender->ID;
63 0 print STDERR "Registered connection $name as " . $sender->ID . "\n";
64 }
65  
66 0 ▶sub handler_add_connection {
Subroutine handler_add_connection: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my ($kernel, $session, $heap, $package, $args)
68 = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
69 0 eval qq{ require $package; };
70 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
71 0 $package->new($args);
72 }
73  
74 # This no longer creates a POE::Session
75 0 ▶sub handler_add_brain {
Subroutine handler_add_brain: not called CC=4 SCAR=30.0
Pod undocumented
76 0 my ($kernel, $session, $heap, $package, $args)
77 = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
78 0 ▶ my $name = $args->{Name} || $package;
Condition0%0/3
$args->{'Name'} || $package
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'Name'} || $package
$args->{'Name'} $package
Truth table0%0/3
A || B
A= $args->{'Name'}B= $package
ABresult
1X1
011
000
79 0 ▶ my $priority = $args->{Priority} || 1;
Condition0%0/2
$args->{'Priority'} || 1
l!l
00
MC/DC0%0/1
$args->{'Priority'} || 1
$args->{'Priority'}
Truth table0%0/2
A
A= $args->{'Priority'}
Aresult
11
00
80  
81 0 eval qq{ require $package; };
82 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
83 0 print STDERR "Amethyst: Failed to add brain $name ($package)\n";
84 0 $heap->{BrainsFailed}->{$name} = 1;
85 }
86 else {
87 0 my $brain = $package->new($args);
88 0 $heap->{Brains}->{$name} = [ $brain, $name, $priority, ];
89 0 $brain->init();
90 }
91 }
92  
93 0 ▶sub handler_connect {
Subroutine handler_connect: not called CC=3 SCAR=24.8
Pod undocumented
94 0 my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
95  
96 0 print STDERR "Amethyst: connecting\n";
97  
98 0 ▶ unless (%{ $heap->{Brains} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%{$heap->{"Brains"};}) 0 0 0
99 0 print STDERR "Amethyst: Warning: No brains!\n";
100 }
101  
102 0 foreach (values %{$heap->{Connections}}) {
103 0 print STDERR "Amethyst: Connecting $_\n";
104 0 $kernel->post($_, 'connect');
105 }
106 }
107  
108 0 ▶sub handler_think {
Subroutine handler_think: not called CC=6 SCAR=37.4
Pod undocumented
109 0 my ($kernel, $session, $heap, $message, $brains, @args) =
110 @_[KERNEL, SESSION, HEAP, ARG0 .. $#_];
111  
112 0 ▶ my @brains = $brains ? @$brains : keys %{$heap->{Brains}};
Branch: 1 branch
BranchTrueFalseTotal
$brains ? : 0 0 0
113  
114 0 foreach my $name (@brains) {
115 0 ▶ if ($heap->{BrainsFailed}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($heap->{"BrainsFailed"}{$name}) 0 0 0
116 0 print STDERR "Amethyst: Cannot think in brain $name: " .
117 "it failed to load at startup\n";
118 0 next;
119 }
120 0 my $brain = $heap->{Brains}->{$name};
121 0 ▶ if ($heap->{BrainsFailed}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($heap->{"BrainsFailed"}{$name}) 0 0 0
122 0 print STDERR "Amethyst: Cannot think in brain $name: " .
123 "no such brain!\n";
124 0 next;
125 }
126 0 ▶ last if $brain->[0]->think($message, @args);
Branch: 1 branch
BranchTrueFalseTotal
if $brain->[0]->think($message, @args) 0 0 0
127 }
128 }
129  
130 1 1;
131  
132 __END__
« Amethyst/Brain/Infobot/Module/Exchange.pm ↑ Summary Amethyst/Connection.pm »