| 1 | package App::Mobirc; |
|---|
| 2 | use Moose; |
|---|
| 3 | with 'App::Mobirc::Role::Pluggable'; |
|---|
| 4 | use 5.00800; |
|---|
| 5 | use Scalar::Util qw/blessed/; |
|---|
| 6 | use POE; |
|---|
| 7 | use App::Mobirc::ConfigLoader; |
|---|
| 8 | use App::Mobirc::Util; |
|---|
| 9 | use App::Mobirc::HTTPD; |
|---|
| 10 | use UNIVERSAL::require; |
|---|
| 11 | use Carp; |
|---|
| 12 | use App::Mobirc::Model::Server; |
|---|
| 13 | use Encode; |
|---|
| 14 | |
|---|
| 15 | our $VERSION = '0.10'; |
|---|
| 16 | |
|---|
| 17 | has server => ( |
|---|
| 18 | is => 'ro', |
|---|
| 19 | isa => 'App::Mobirc::Model::Server', |
|---|
| 20 | default => sub { App::Mobirc::Model::Server->instance() }, |
|---|
| 21 | handles => [qw/add_channel delete_channel channels get_channel delete_channel/], # for backward compatibility |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | has config => ( |
|---|
| 25 | is => 'ro', |
|---|
| 26 | isa => 'HashRef', |
|---|
| 27 | required => 1, |
|---|
| 28 | ); |
|---|
| 29 | |
|---|
| 30 | my $context; |
|---|
| 31 | sub context { $context } |
|---|
| 32 | |
|---|
| 33 | around 'new' => sub { |
|---|
| 34 | my ($next, $class, $config_stuff) = @_; |
|---|
| 35 | my $config = App::Mobirc::ConfigLoader->load($config_stuff); |
|---|
| 36 | |
|---|
| 37 | my $self = $next->( $class, config => $config ); |
|---|
| 38 | $self->load_plugins; |
|---|
| 39 | |
|---|
| 40 | $context = $self; |
|---|
| 41 | |
|---|
| 42 | return $self; |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | sub run { |
|---|
| 46 | my $self = shift; |
|---|
| 47 | die "this is instance method" unless blessed $self; |
|---|
| 48 | |
|---|
| 49 | for my $code (@{$self->get_hook_codes('run_component')}) { |
|---|
| 50 | $code->($self); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | App::Mobirc::HTTPD->init($self->config); |
|---|
| 54 | |
|---|
| 55 | $poe_kernel->run(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | 1; |
|---|
| 59 | __END__ |
|---|
| 60 | |
|---|
| 61 | =head1 NAME |
|---|
| 62 | |
|---|
| 63 | App::Mobirc - pluggable IRC to HTTP gateway |
|---|
| 64 | |
|---|
| 65 | =head1 DESCRIPTION |
|---|
| 66 | |
|---|
| 67 | mobirc is a pluggable IRC to HTTP gateway for mobile phones. |
|---|
| 68 | |
|---|
| 69 | =head1 METHODS |
|---|
| 70 | |
|---|
| 71 | =over 4 |
|---|
| 72 | |
|---|
| 73 | =item context |
|---|
| 74 | |
|---|
| 75 | get a context object |
|---|
| 76 | |
|---|
| 77 | =item new |
|---|
| 78 | |
|---|
| 79 | create a instance of context object. |
|---|
| 80 | |
|---|
| 81 | =item load_plugins |
|---|
| 82 | |
|---|
| 83 | load plugins |
|---|
| 84 | |
|---|
| 85 | =item config |
|---|
| 86 | |
|---|
| 87 | get a global configuration |
|---|
| 88 | |
|---|
| 89 | =item run |
|---|
| 90 | |
|---|
| 91 | run server |
|---|
| 92 | |
|---|
| 93 | =item register_hook |
|---|
| 94 | |
|---|
| 95 | register hook |
|---|
| 96 | |
|---|
| 97 | =item get_hook_codes |
|---|
| 98 | |
|---|
| 99 | get hook codes |
|---|
| 100 | |
|---|
| 101 | =item add_channel |
|---|
| 102 | |
|---|
| 103 | register channel object |
|---|
| 104 | |
|---|
| 105 | =item channels |
|---|
| 106 | |
|---|
| 107 | get a channel objects. |
|---|
| 108 | |
|---|
| 109 | =item get_channel |
|---|
| 110 | |
|---|
| 111 | get a channel |
|---|
| 112 | |
|---|
| 113 | =item delete_channel |
|---|
| 114 | |
|---|
| 115 | delete channel |
|---|
| 116 | |
|---|
| 117 | =back |
|---|
| 118 | |
|---|
| 119 | =head1 TODO |
|---|
| 120 | |
|---|
| 121 | use HTTP::MobileAttribute instead of HTTP::MobileAgent |
|---|
| 122 | |
|---|
| 123 | =head1 CODE COVERAGE |
|---|
| 124 | |
|---|
| 125 | I use Devel::Cover to test the code coverage of my tests, below is the Devel::Cover report on this module test suite. |
|---|
| 126 | |
|---|
| 127 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
|---|
| 128 | File stmt bran cond sub pod time total |
|---|
| 129 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
|---|
| 130 | blib/lib/App/Mobirc.pm 80.0 35.7 62.5 87.0 0.0 3.0 66.5 |
|---|
| 131 | ...lib/App/Mobirc/Channel.pm 77.3 53.6 66.7 81.2 14.3 0.7 68.3 |
|---|
| 132 | ...pp/Mobirc/ConfigLoader.pm 94.3 50.0 72.7 100.0 0.0 8.2 81.8 |
|---|
| 133 | blib/lib/App/Mobirc/HTTPD.pm 63.3 0.0 0.0 85.2 0.0 1.1 56.4 |
|---|
| 134 | ...obirc/HTTPD/Controller.pm 38.9 19.4 0.0 61.3 0.0 1.0 35.6 |
|---|
| 135 | ...pp/Mobirc/HTTPD/Router.pm 40.9 0.0 n/a 85.7 0.0 0.1 30.0 |
|---|
| 136 | ...lib/App/Mobirc/Message.pm 100.0 n/a n/a 100.0 100.0 0.3 100.0 |
|---|
| 137 | ...n/Authorizer/BasicAuth.pm 48.0 0.0 0.0 57.1 0.0 0.0 38.1 |
|---|
| 138 | ...ugin/Authorizer/Cookie.pm 44.7 0.0 0.0 53.8 0.0 0.0 37.8 |
|---|
| 139 | ...horizer/EZSubscriberID.pm 48.0 0.0 0.0 57.1 0.0 0.0 40.0 |
|---|
| 140 | .../Authorizer/SoftBankID.pm 52.2 0.0 0.0 57.1 0.0 0.0 42.1 |
|---|
| 141 | ...in/Component/IRCClient.pm 83.2 33.3 41.7 83.3 0.0 4.7 72.1 |
|---|
| 142 | .../Mobirc/Plugin/DocRoot.pm 80.6 25.0 n/a 75.0 0.0 10.0 69.8 |
|---|
| 143 | ...PS/InvGeocoder/EkiData.pm 93.8 75.0 n/a 100.0 0.0 1.0 90.9 |
|---|
| 144 | ...S/InvGeocoder/Nishioka.pm 96.7 50.0 n/a 100.0 0.0 0.6 92.5 |
|---|
| 145 | ...TMLFilter/CompressHTML.pm 90.9 n/a n/a 80.0 0.0 0.1 85.7 |
|---|
| 146 | ...lter/ConvertPictograms.pm 84.6 n/a n/a 80.0 0.0 0.3 78.9 |
|---|
| 147 | ...n/HTMLFilter/DoCoMoCSS.pm 100.0 50.0 n/a 100.0 0.0 65.7 91.2 |
|---|
| 148 | ...n/IRCCommand/TiarraLog.pm 21.4 0.0 0.0 57.1 0.0 0.0 18.4 |
|---|
| 149 | ...geBodyFilter/Clickable.pm 92.8 83.3 72.7 83.3 0.0 1.3 85.1 |
|---|
| 150 | ...ageBodyFilter/IRCColor.pm 87.9 81.0 100.0 81.8 0.0 0.7 83.7 |
|---|
| 151 | blib/lib/App/Mobirc/Util.pm 100.0 50.0 n/a 100.0 0.0 1.1 86.3 |
|---|
| 152 | Total 69.6 36.1 36.0 79.2 2.8 100.0 61.8 |
|---|
| 153 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
|---|
| 154 | |
|---|
| 155 | =head1 AUTHOR |
|---|
| 156 | |
|---|
| 157 | Tokuhiro Matsuno and Mobirc AUTHORS. |
|---|
| 158 | |
|---|
| 159 | =head1 LICENSE |
|---|
| 160 | |
|---|
| 161 | GPL 2.0 or later. |
|---|