Net.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 76 CC 4 SCAR 13.1
CC
4
Cov
0%
bot_net
6.0
config
6.0
log
6.0
CRAP 3.7
1 use strict;
2 use warnings;
3  
4 package Bot::Net;
5 use base qw/ Class::Data::Inheritable /;
6  
7 our $VERSION = '0.1.0';
8  
9 use Bot::Net::Config;
10 use Bot::Net::Log;
11  
12 __PACKAGE__->mk_classdata(qw/ _bot_net /);
13  
14 =head1 NAME
15  
16 Bot::Net - run your very own IRC bot net
17  
18 =head1 SYNOPSIS
19  
20 If you're just using a L<Bot::Net>:
21  
22 cd MyBotNet
23 bin/botnet run --server Main
24 bin/botnet run --bot SomeBot
25  
26 To create a new L<Bot::Net> application:
27  
28 bin/botnet net --name MyBotNet
29  
30 TODO XXX FIXME Document automatic creation of new bots and servers...
31  
32 If you're developing a new bot or something, you might find these useful:
33  
34 Bot::Net->log->debug("Debug message.");
35 Bot::Net->log->error("Error message.");
36  
37 my $value = Bot::Net->config->bot('MyBot')->{'config'}{'value'};
38  
39 =head1 DESCRIPTION
40  
41 B<EXPERIMENTAL:> This module has just barely left the proof-of-concept phase. Much of the API is fluid and changing. If you're interested in contributing, please contact me at my email address at the bottom.
42  
43 A nice way to create bots, networks of bots, and servers that run them. Currently, this system only provides tools for building IRC bots, but additional protocols could be added in the future. The aim is not to tie the system to any one architecture for the bots, but provide an easy way to build them and verify that they do what you want.
44  
45 =head2 GOALS
46  
47 The aim of this system is to provide a tool for creating a botnet for handling parallel tasks with communication primarily happening over IRC. The eventual goals of the system include:
48  
49 =over
50  
51 =item *
52  
53 Provide easy to build and easy to understand mechanisms for building semi-autonomous agent-based systems (bots).
54  
55 =item *
56  
57 Automatically build the scaffolding for a L<Bot::Net> application, automatically create stubs for bots and servers, and generally give you some tools to get started quickly.
58  
59 =item *
60  
61 Provide a declarative syntax for creating bots and bot components.
62  
63 =item *
64  
65 Tools for initializing and managing the lifecycle of all your bots.
66  
67 =item *
68  
69 A server environment for helping you run your bots on one or more hosts that can communicate with one another.
70  
71 =item *
72  
73 A verification system for telling you whether or not your bots will talk to each other without getting confused or fail.
74  
75 =back
76  
77 =head2 WHY?
78  
79 First, because breaking certain tasks into small hunks that can be handled by semi-autonomous agentsis a handy way to think about some problems.
80  
81 The original problem I wrote this system for is to handle the synchronization of data between lots of hosts. I had bots for pulling bits of data from each host, other bots for pushing bits of data back to each host, bots for pulling data from one host and pushing to another, bots for filtering the data so that it's in the correct format, etc.
82  
83 It quickly became a pain, so I built this to take away the pain.
84  
85 Previously, I wrote another system, L<FleetConf>, to handle a very similar task. However, I am not very happy with how that turned out, so learning from my work there, I've built this system.
86  
87 =head1 THIS OBJECT
88  
89 This is the central singleton providing some basic services used by just about everything in the L<Bot::Net> system.
90  
91 =head1 METHODS
92  
93 =head2 bot_net
94  
95 Returns the singleton object. Usually, you don't need to call this directly since all the L<Bot::Net> methods call this internally.
96  
97 =cut
98  
99 sub bot_net {
100 my $class = shift;
101 unless ($class->_bot_net) {
102 $class->_bot_net(bless {}, $class);
103 }
104 return $class->_bot_net;
105 }
106  
107 =head2 config
108  
109 Return the configuration data for this application instance. See L<Bot::Net::Config> for additioanl details.
110  
111 =cut
112  
113 sub config {
114 my $class = shift;
115 my $self = $class->bot_net;
116  
117 if (not defined $self->{config}) {
118 $self->{config} = Bot::Net::Config->new;
119 }
120  
121 return $self->{config};
122 }
123  
124 =head2 log NAME
125  
126 Retrieves a logger object for this application. If given a name, it will return a specific named logger. Otherwise, it returns the application default logger, named "Bot::Net".
127  
128 See L<Bot::Net::Log>.
129  
130 =cut
131  
132 sub log {
133 my $class = shift;
134 my $self = $class->bot_net;
135 my $name = shift || eval { Bot::Net->config->net('ApplicationClass') }
136 || 'Bot::Net';
137  
138 if (not defined $self->{log}) {
139 $self->{log} = Bot::Net::Log->new;
140 }
141  
142 return $self->{log}->get_logger($name);
143 }
144  
145 =head2 net_class NAMES
146  
147 Given a list of names, it creates a class name for the current L<Bot::Net> application.
148  
149 # Find the name of the Chatbot::Eliza bot in the local app
150 my $class = Bot::Net->net_class('Bot', 'Chatbot', 'Eliza');
151  
152 =cut
153  
154 sub net_class {
155 my $class = shift;
156 my $app_class = $class->config->net('ApplicationClass');
157  
158 return scalar join '::', $app_class, @_;
159 }
160  
161 =head2 short_name_for_bot CLASS
162  
163 Returns the name of the bot.
164  
165 =cut
166  
167 sub short_name_for_bot {
168 my $class = shift;
169 my $bot_class = shift;
170  
171 my $app_class = $class->config->net('ApplicationClass');
172  
173 $bot_class =~ s/^\Q$app_class\E::Bot:://;
174  
175 return $bot_class;
176 }
177  
178 =head2 short_name_for_server CLASS
179  
180 Returns the name of the server.
181  
182 =cut
183  
184 sub short_name_for_server {
185 my $class = shift;
186 my $server_class = shift;
187  
188 my $app_class = $class->config->net('ApplicationClass');
189  
190 $server_class =~ s/^\Q$app_class\E::Server:://;
191  
192 return $server_class;
193 }
194  
195 =head1 AUTHORS
196  
197 Andrew Sterling Hanenkamp C<< <hanenkamp@cpan.org> >>
198  
199 =head1 COPYRIGHT AND LICENSE
200  
201 Copyright 2007 Boomer Consulting, Inc. All Rights Reserved.
202  
203 This program is free software and may be modified and distributed under the same terms as Perl itself.
204  
205 =cut
206  
207 1;