Changeset 13013
- Timestamp:
- 06/01/08 23:00:19 (5 years ago)
- Location:
- lang/perl/mobirc/trunk
- Files:
-
- 3 added
- 1 removed
- 34 modified
- 1 moved
-
CONCEPT (modified) (1 diff)
-
Makefile.PL (modified) (1 diff)
-
config.yaml.sample (modified) (3 diffs)
-
lib/App/Mobirc.pm (modified) (4 diffs)
-
lib/App/Mobirc/HTTPD/C.pm (modified) (2 diffs)
-
lib/App/Mobirc/HTTPD/C/Mobile.pm (modified) (1 diff)
-
lib/App/Mobirc/HTTPD/Handler.pm (modified) (4 diffs)
-
lib/App/Mobirc/HTTPD/Template/IRCMessage.pm (modified) (2 diffs)
-
lib/App/Mobirc/Model/Channel.pm (modified) (1 diff)
-
lib/App/Mobirc/Plugin/Authorizer/BasicAuth.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/Authorizer/Cookie.pm (modified) (4 diffs)
-
lib/App/Mobirc/Plugin/Authorizer/DoCoMoGUID.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/Authorizer/EZSubscriberID.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/Authorizer/SoftBankID.pm (modified) (1 diff)
-
lib/App/Mobirc/Plugin/Component/IRCClient.pm (modified) (24 diffs)
-
lib/App/Mobirc/Plugin/Component/Twitter.pm (modified) (6 diffs)
-
lib/App/Mobirc/Plugin/DocRoot.pm (modified) (3 diffs)
-
lib/App/Mobirc/Plugin/GPS.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/HTMLFilter/CompressHTML.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/HTMLFilter/ConvertPictograms.pm (modified) (1 diff)
-
lib/App/Mobirc/Plugin/HTMLFilter/DoCoMoCSS.pm (modified) (3 diffs)
-
lib/App/Mobirc/Plugin/HTMLFilter/StickyTime.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/IRCCommand/TiarraLog.pm (modified) (2 diffs)
-
lib/App/Mobirc/Plugin/MessageBodyFilter/Clickable.pm (modified) (7 diffs)
-
lib/App/Mobirc/Plugin/MessageBodyFilter/IRCColor.pm (modified) (2 diffs)
-
lib/App/Mobirc/Role/Pluggable.pm (deleted)
-
lib/App/Mobirc/Validator.pm (added)
-
t/HTTPD/Template/IRCMessage.t (modified) (1 diff)
-
t/Plugins/Component (added)
-
t/Plugins/Component/IRCClient.t (moved) (moved from lang/perl/mobirc/trunk/t/07-Component-IRCClient.t) (2 diffs)
-
t/Plugins/DocRoot.t (modified) (2 diffs)
-
t/Plugins/Filter/clickable.t (modified) (6 diffs)
-
t/Plugins/Filter/decorate-irc-color.t (modified) (2 diffs)
-
t/Plugins/Filter/no-decorate-irc-color.t (modified) (2 diffs)
-
t/Plugins/GPS.t (added)
-
t/Plugins/HTMLFilter/CompressHTML.t (modified) (2 diffs)
-
t/Plugins/HTMLFilter/ConvertPictograms.t (modified) (2 diffs)
-
t/Plugins/HTMLFilter/DoCoMoCSS.t (modified) (3 diffs)
-
t/Plugins/HTMLFilter/StickyTime.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/mobirc/trunk/CONCEPT
r12896 r13013 11 11 - 1.00 マデニヤルコト 12 12 -- MooseX::Plaggerize べーすニ移行 13 --- run_hook_first を移動させる 14 --- run_hook_filter を移動させる 15 --- App::Mobirc::Plugin::Component::XMPP を復活させる 13 16 -- C からよばれる Template はすべて validate() をつかう 17 -- DocRoot の完全分離 18 -- HTMLFilter::StickyTime => StickyTime. 19 -- and preload StickyTime plugin. 20 -- HTTPD::* => Web::* 21 -- hirose31's Groups => Hook. 22 -- validate_hook を、もうちょいなんとかかっこよく実装したい。 23 -
lang/perl/mobirc/trunk/Makefile.PL
r12903 r13013 7 7 # moooooose 8 8 requires 'Moose' => '0.48'; 9 requires 'MooseX::Plaggerize' => '0.03'; 9 10 10 11 # http-engine -
lang/perl/mobirc/trunk/config.yaml.sample
r7461 r13013 10 10 11 11 plugin: 12 - module: App::Mobirc::Plugin::HTMLFilter::DoCoMoCSS13 - module: App::Mobirc::Plugin::IRCCommand::TiarraLog14 - module: A pp::Mobirc::Plugin::Authorizer::Cookie12 - module: HTMLFilter::DoCoMoCSS 13 - module: IRCCommand::TiarraLog 14 - module: Authorizer::Cookie 15 15 config: 16 16 password: 1152 17 - module: A pp::Mobirc::Plugin::Authorizer::BasicAuth17 - module: Authorizer::BasicAuth 18 18 config: 19 19 username: netwatcher 20 20 password: 0721 21 # - module: A pp::Mobirc::Plugin::Authorizer::EZSubscriberID21 # - module: Authorizer::EZSubscriberID 22 22 # config: 23 23 # au_subscriber_id: 25253252_oe.ezweb.ne.jp 24 - module: App::Mobirc::Plugin::HTMLFilter::ConvertPictograms25 - module: App::Mobirc::Plugin::MessageBodyFilter::Clickable24 - module: HTMLFilter::ConvertPictograms 25 - module: MessageBodyFilter::Clickable 26 26 config: 27 27 au_pcsv: 0 … … 30 30 # accept_schemes: [mailto, tel] 31 31 # redirector: http://www.google.com/url?sa=D&q= 32 - module: App::Mobirc::Plugin::MessageBodyFilter::IRCColor32 - module: MessageBodyFilter::IRCColor 33 33 config: 34 34 # no_decorate: 0 35 35 36 - module: App::Mobirc::Plugin::Component::IRCClient36 - module: Component::IRCClient 37 37 config: 38 39 38 server: 127.0.0.1 40 39 port: 252322 … … 55 54 - jagayama 56 55 57 # - module: App::Mobirc::Plugin::DocRoot56 # - module: DocRoot 58 57 # config: 59 58 # root: /foo/ -
lang/perl/mobirc/trunk/lib/App/Mobirc.pm
r12896 r13013 1 1 package App::Mobirc; 2 2 use Moose; 3 with 'App::Mobirc::Role:: Pluggable', 'App::Mobirc::Role::Context';3 with 'App::Mobirc::Role::Context', 'MooseX::Plaggerize', 'MooseX::Plaggerize::PluginLoader'; 4 4 use 5.00800; 5 5 use Scalar::Util qw/blessed/; … … 33 33 34 34 my $self = $next->( $class, config => $config ); 35 $self->load_plugins; 35 36 $self->_load_plugins(); 36 37 37 38 return $self; 38 39 }; 40 41 sub _load_plugins { 42 my $self = shift; 43 for my $plugin (@{ $self->config->{plugin} }) { 44 $plugin->{module} =~ s/^App::Mobirc::Plugin:://; 45 $self->load_plugin( $plugin ); 46 } 47 } 39 48 40 49 sub run { … … 42 51 die "this is instance method" unless blessed $self; 43 52 44 for my $code (@{$self->get_hook_codes('run_component')}) { 45 $code->($self); 46 } 53 $self->run_hook('run_component'); 47 54 48 55 App::Mobirc::HTTPD->init($self->config); … … 89 96 90 97 register hook 91 92 =item get_hook_codes93 94 get hook codes95 96 =item add_channel97 98 register channel object99 100 =item channels101 102 get a channel objects.103 104 =item get_channel105 106 get a channel107 108 =item delete_channel109 110 delete channel111 98 112 99 =back -
lang/perl/mobirc/trunk/lib/App/Mobirc/HTTPD/C.pm
r12654 r13013 21 21 my ( $c, $out ) = @_; 22 22 23 $out = _html_filter($c, $out);23 ($c, $out) = context->run_hook_filter('html_filter', $c, $out); 24 24 my $content = encode( $c->req->mobile_agent->encoding, $out); 25 25 … … 39 39 $c->res->body( $content ); 40 40 41 for my $code (@{context->get_hook_codes('response_filter')}) { 42 $code->($c); 43 } 41 context->run_hook('response_filter', $c); 44 42 } 45 43 46 sub _html_filter {47 my $c = shift;48 my $content = shift;49 50 for my $code (@{context->get_hook_codes('html_filter')}) {51 $content = $code->($c, $content);52 }53 54 $content;55 }56 57 58 44 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/HTTPD/C/Mobile.pm
r12885 r13013 122 122 recent_mode => $c->req->params->{recent_mode}, 123 123 message => $c->req->params->{'msg'} || '', 124 channel_page_option => [ 125 map { $_->( $channel, $c ) } 126 @{ context->get_hook_codes('channel_page_option') } 127 ], 124 channel_page_option => context->run_hook('channel_page_option', $channel, $c), 128 125 irc_nick => irc_nick, 129 126 } -
lang/perl/mobirc/trunk/lib/App/Mobirc/HTTPD/Handler.pm
r12867 r13013 12 12 my $dve = Data::Visitor::Encode->new; 13 13 14 sub context () { App::Mobirc->context } ## no critic 15 14 16 sub handler { 15 17 my $c = shift; 16 18 17 for my $code (@{App::Mobirc->context->get_hook_codes('request_filter')}) { 18 $code->($c); 19 } 19 context->run_hook('request_filter', $c); 20 20 21 21 if (authorize($c)) { … … 24 24 $c->res->set_http_response($response); 25 25 } 26 for my $code (@{App::Mobirc->context->get_hook_codes('response_filter')}) { 27 $code->($c); 28 } 26 context->run_hook('response_filter', $c); 29 27 } else { 30 28 $c->res->status(401); … … 35 33 sub authorize { 36 34 my $c = shift; 37 for my $code (@{App::Mobirc->context->get_hook_codes('authorize')}) { 38 if ($code->($c)) { 39 DEBUG "AUTHORIZATION SUCCEEDED"; 40 return 1; # authorization succeeded. 41 } 35 36 if (context->run_hook_first('authorize', $c)) { 37 DEBUG "AUTHORIZATION SUCCEEDED"; 38 return 1; # authorization succeeded. 39 } else { 40 return 0; # authorization failed 42 41 } 43 return 0; # authorization failed44 42 } 45 43 … … 51 49 unless ($rule) { 52 50 # hook by plugins 53 for my $code (@{App::Mobirc->context->get_hook_codes('httpd')}) { 54 my $finished = $code->($c, $c->req->uri->path); 55 if ($finished) { 56 # XXX we should use html filter? 57 return; 58 } 51 if (context->run_hook_first( 'httpd', ( $c, $c->req->uri->path ) ) ) { 52 # XXX we should use html filter? 53 return; 59 54 } 60 55 -
lang/perl/mobirc/trunk/lib/App/Mobirc/HTTPD/Template/IRCMessage.pm
r12887 r13013 58 58 my $g = {}; 59 59 for my $p ( @{ App::Mobirc->context->config->{plugin} || [] } ) { 60 if ( $p->{module} eq 'App::Mobirc::Plugin::Component::IRCClient' ) {60 if ( $p->{module} =~ 'Component::IRCClient' ) { 61 61 $g = $p->{config}->{groups} if exists $p->{config}->{groups}; 62 62 last; … … 93 93 my ( $self, $class, $body ) = validate_pos( @_, OBJECT, SCALAR, SCALAR ); 94 94 95 my $c = App::Mobirc->context;96 my $codes = $c->get_hook_codes('message_body_filter') || [];97 98 95 $body = encode_entities($body, q{<>&"'}); 99 for my $filter ( @{ $codes } ) { 100 $body = $filter->($body); 101 } 96 ($body, ) = App::Mobirc->context->run_hook_filter('message_body_filter', $body); 102 97 103 98 span { attr { class => $class } -
lang/perl/mobirc/trunk/lib/App/Mobirc/Model/Channel.pm
r12644 r13013 102 102 my ($self, $command) = @_; 103 103 104 for my $code (@{$self->{global_context}->get_hook_codes('process_command')}) { 105 my $ret = $code->($self->{global_context}, $command, $self); 106 last if $ret; 107 } 104 $self->{global_context}->run_hook_first('process_command', $command, $self); 108 105 } 109 106 -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Authorizer/BasicAuth.pm
r5980 r13013 1 1 package App::Mobirc::Plugin::Authorizer::BasicAuth; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use Carp; 5 5 use App::Mobirc::Util; 6 6 7 sub register { 8 my ($class, $global_context, $conf) = @_; 9 10 $global_context->register_hook( 11 'authorize' => sub { my $c = shift; _authorize($c, $conf) }, 12 ); 13 } 14 15 sub _authorize { 16 my ( $c, $conf ) = @_; 7 hook authorize => sub { 8 my ( $self, $global_context, $c, $conf ) = @_; 17 9 18 10 DEBUG "Basic Auth..."; … … 30 22 return false; 31 23 } 32 } 24 }; 33 25 34 26 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Authorizer/Cookie.pm
r12642 r13013 1 1 package App::Mobirc::Plugin::Authorizer::Cookie; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use App::Mobirc::Util; 5 5 use Carp; … … 7 7 use Digest::MD5 (); 8 8 use Encode; 9 use App::Mobirc::Validator; 9 10 10 our $SALT = 'CSS Nite'; 11 has password => ( 12 is => 'ro', 13 isa => 'Str', 14 required => 1, 15 ); 11 16 12 sub register { 13 my ($class, $global_context, $conf) = @_; 17 has expires => ( 18 is => 'ro', 19 isa => 'Str', 20 default => '+7d', 21 ); 14 22 15 $global_context->register_hook( 16 'authorize' => sub { my $c = shift; _authorize($c, $conf) }, 17 ); 18 $global_context->register_hook( 19 'response_filter' => sub { my ($c, ) = @_; _set_cookie($c, $conf) }, 20 ); 21 } 23 hook authorize => sub { 24 my ( $self, $global_context, $c, ) = validate_hook('authorize', @_); 22 25 23 # comfort 24 sub _calc_digest { 25 my ($password, ) = @_; 26 27 return Digest::MD5::md5_hex( "$password,$SALT" ); 28 } 29 30 sub _authorize { 31 my ( $c, $conf ) = @_; 32 33 my $cookie_str = $c->{req}->header('Cookie'); 26 my $cookie_str = $c->req->header('Cookie'); 34 27 unless ($cookie_str) { 35 28 DEBUG "cookie header is empty"; … … 37 30 } 38 31 39 my %cookie = CGI::Cookie->parse($cookie_str); 40 if ( $cookie{mobirc_key} && $cookie{mobirc_key}->value eq _calc_digest($conf->{password}) ) 41 { 32 my %cookie = CGI::Cookie->parse($cookie_str); # TODO: use HTTP::Engine::Request's stuff! 33 if ( $cookie{mobirc_key} && $cookie{mobirc_key}->value eq _calc_digest($self->password) ) { 42 34 DEBUG "cookie auth succeeded"; 43 35 return true; … … 47 39 return false; 48 40 } 49 } 41 }; 50 42 51 sub _set_cookie { 52 my ($c, $conf) = @_; 53 54 my $password = $conf->{password} or croak "conf->{password} missing"; 43 hook response_filter => sub { 44 my ($self, $global_context, $c) = validate_hook('response_filter', @_); 55 45 56 46 $c->res->cookies->{mobirc_key} = CGI::Cookie->new( 57 47 -name => 'mobirc_key', 58 -value => _calc_digest($ password),59 -expires => $ conf->{expires} || '+7d',48 -value => _calc_digest($self->password), 49 -expires => $self->expires, 60 50 ); 51 }; 52 53 our $SALT = 'CSS Nite'; 54 sub _calc_digest { 55 my ($password, ) = @_; 56 return Digest::MD5::md5_hex( "$password,$SALT" ); 61 57 } 62 58 -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Authorizer/DoCoMoGUID.pm
r12868 r13013 1 1 package App::Mobirc::Plugin::Authorizer::DoCoMoGUID; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use Carp; 5 5 use App::Mobirc::Util; 6 use HTML::StickyQuery::DoCoMoGUID; 6 7 7 use HTML::StickyQuery::DoCoMoGUID; 8 sub register { 9 my ($class, $global_context, $conf) = @_; 8 has docomo_guid => ( 9 is => 'ro', 10 isa => 'Str', 11 required => 1, 12 ); 10 13 11 $global_context->register_hook( 12 'authorize' => sub { my $c = shift; _authorize($c, $conf) } 13 ); 14 $global_context->register_hook( 15 'html_filter' => \&_html_filter_docomo_guid, 16 ); 17 } 14 hook authorize => sub { 15 my ( $self, $global_context, $c, ) = @_; 18 16 19 sub _authorize { 20 my ( $c, $conf ) = @_; 21 22 DEBUG __PACKAGE__; 23 24 unless ($conf->{docomo_guid}) { 25 croak "missing docomo_guid"; 26 } 27 28 my $subno = $c->{req}->header('x-dcmguid'); 29 if ( $subno && $subno eq $conf->{docomo_guid} ) { 17 my $subno = $c->req->header('x-dcmguid'); 18 if ( $subno && $subno eq $self->docomo_guid ) { 30 19 DEBUG "SUCESS AT DocomoGUID"; 31 20 return true; … … 33 22 return false; 34 23 } 35 } 24 }; 36 25 37 sub _html_filter_docomo_guid{38 my ($ c, $content) = @_;26 hook 'html_filter' => sub { 27 my ($self, $global_context, $c, $content) = @_; 39 28 40 29 DEBUG "Filter DoCoMoGUID"; 41 30 return $content unless $c->req->mobile_agent->is_docomo; 42 43 return HTML::StickyQuery::DoCoMoGUID->new()->sticky( scalarref => \$content, ); 44 } 31 return ($c, HTML::StickyQuery::DoCoMoGUID->new()->sticky( scalarref => \$content, )); 32 }; 45 33 46 34 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Authorizer/EZSubscriberID.pm
r5980 r13013 1 1 package App::Mobirc::Plugin::Authorizer::EZSubscriberID; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use Carp; 5 5 use App::Mobirc::Util; 6 6 7 sub register { 8 my ($class, $global_context, $conf) = @_; 7 has 'au_subscriber_id' => ( 8 is => 'ro', 9 isa => 'Str', 10 required => 1, 11 ); 9 12 10 $global_context->register_hook( 11 'authorize' => sub { my $c = shift; _authorize($c, $conf) }, 12 ); 13 } 13 hook authorize => sub { 14 my ( $self, $global_context, $c, ) = @_; 14 15 15 sub _authorize { 16 my ( $c, $conf ) = @_; 17 18 DEBUG __PACKAGE__; 19 20 unless ($conf->{au_subscriber_id}) { 21 croak "missing au_subscriber_id"; 22 } 23 24 my $subno = $c->{req}->header('x-up-subno'); 25 if ( $subno && $subno eq $conf->{au_subscriber_id} ) { 16 my $subno = $c->req->header('x-up-subno'); 17 if ( $subno && $subno eq $self->au_subscriber_id ) { 26 18 DEBUG "SUCESS AT EZSubscriberID"; 27 19 return true; … … 29 21 return false; 30 22 } 31 } 23 }; 32 24 33 25 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Authorizer/SoftBankID.pm
r5980 r13013 1 1 package App::Mobirc::Plugin::Authorizer::SoftBankID; 2 # vim:expandtab:3 2 use strict; 4 use warnings;3 use MooseX::Plaggerize::Plugin; 5 4 use Carp; 6 5 use App::Mobirc::Util; 7 6 8 sub register { 9 my ($class, $global_context, $conf) = @_; 7 has jphone_uid => ( 8 is => 'ro', 9 isa => 'Str', 10 required => 1, 11 ); 10 12 11 $global_context->register_hook( 12 'authorize' => sub { my $c = shift; _authorize($c, $conf) }, 13 ); 14 } 13 hook authorize => sub { 14 my ( $self, $global_context, $c ) = @_; 15 15 16 sub _authorize { 17 my ( $c, $conf ) = @_; 18 19 unless ($conf->{jphone_uid}) { 20 croak "missing jphone_uid; specify your x-jphone-uid string."; 21 } 22 23 my $uid = $c->{req}->header('x-jphone-uid'); 24 if ( $uid && $uid eq $conf->{jphone_uid} ) { 16 my $uid = $c->req->header('x-jphone-uid'); 17 if ( $uid && $uid eq $self->jphone_uid ) { 25 18 return true; 26 19 } else { 27 20 return false; 28 21 } 29 } 22 }; 30 23 31 24 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Component/IRCClient.pm
r12148 r13013 1 1 package App::Mobirc::Plugin::Component::IRCClient; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 5 5 use POE; … … 13 13 use App::Mobirc::Util; 14 14 15 sub register { 16 my ($class, $global_context, $conf) = @_; 17 18 DEBUG "register ircclient component"; 19 $conf->{ping_delay} ||= 30; 20 $conf->{reconnect_delay} ||= 10; 21 22 $global_context->register_hook( 23 'run_component' => sub { _init($conf, shift) }, 24 ); 25 $global_context->register_hook( 26 'process_command' => sub { my ($global_context, $command, $channel) = @_; _process_command($conf, $global_context, $command, $channel) }, 27 ); 28 } 29 30 sub _process_command { 31 my ($conf, $global_context, $command, $channel) = @_; 32 33 my $irc_incode = $conf->{incode}; 34 if ($command && $channel->name =~ /^[#*%]/) { 35 if ($command =~ m{^/}) { 15 has ping_delay => ( 16 is => 'ro', 17 isa => 'Int', 18 default => 30, 19 ); 20 21 has reconnect_delay => ( 22 is => 'ro', 23 isa => 'Int', 24 default => 10, 25 ); 26 27 has incode => ( 28 is => 'ro', 29 isa => 'Str', 30 default => 'UTF-8', 31 ); 32 33 has nick => ( 34 is => 'ro', 35 isa => 'Str', 36 required => 1, 37 ); 38 39 has username => ( 40 is => 'ro', 41 isa => 'Str', 42 default => 'mobirc user', 43 ); 44 45 has groups => ( 46 is => 'ro', 47 isa => 'HashRef', 48 ); 49 50 has desc => ( 51 is => 'ro', 52 isa => 'Str', 53 default => '', 54 ); 55 56 has server => ( 57 is => 'ro', 58 isa => 'Str', 59 required => 1, 60 ); 61 62 has port => ( 63 is => 'ro', 64 isa => 'Int', 65 required => 1, 66 ); 67 68 has password => ( 69 is => 'ro', 70 isa => 'Str', 71 ); 72 73 hook process_command => sub { 74 my ( $self, $global_context, $command, $channel ) = @_; 75 76 my $irc_incode = $self->incode; 77 if ( $command && $channel->name =~ /^[#*%]/ ) { 78 if ( $command =~ m{^/} ) { 36 79 DEBUG "SENDING COMMAND"; 37 80 $command =~ s!^/!!g; … … 41 84 $command; 42 85 43 $poe_kernel->post('mobirc_irc', @args); 44 } else { 86 $poe_kernel->post( 'mobirc_irc', @args ); 87 } 88 else { 45 89 DEBUG "NORMAL PRIVMSG"; 46 90 47 91 $poe_kernel->post( 'mobirc_irc', 48 92 privmsg => encode( $irc_incode, $channel->name ) => 49 encode( $irc_incode, $command ) );93 encode( $irc_incode, $command ) ); 50 94 51 95 DEBUG "Sending command $command"; 96 52 97 # FIXME: httpd $B4X78$J$$7o(B 53 if ( $global_context->config->{httpd}->{echo} eq true) {98 if ( $global_context->config->{httpd}->{echo} eq true ) { 54 99 $channel->add_message( 55 100 App::Mobirc::Model::Message->new( 56 101 who => decode( 57 102 $irc_incode, 58 $poe_kernel->alias_resolve('irc_session')->get_heap->{irc}->nick_name 103 $poe_kernel->alias_resolve('irc_session') 104 ->get_heap->{irc}->nick_name 59 105 ), 60 106 body => $command, … … 67 113 } 68 114 return false; 69 } 70 71 sub _init{72 my ( $config, $global_context) = @_;115 }; 116 117 hook 'run_component' => sub { 118 my ( $self, $global_context ) = @_; 73 119 74 120 DEBUG "initialize ircclient"; 121 75 122 # irc component 76 123 my $irc = POE::Component::IRC->spawn( 77 124 Alias => 'mobirc_irc', 78 Nick => $ config->{nick},79 Username => $ config->{username},80 Ircname => $ config->{desc},81 Server => $ config->{server},82 Port => $ config->{port},83 Password => $ config->{password}125 Nick => $self->nick, 126 Username => $self->username, 127 Ircname => $self->desc, 128 Server => $self->server, 129 Port => $self->port, 130 Password => $self->password, 84 131 ); 85 132 … … 88 135 seen_traffic => false, 89 136 disconnect_msg => true, 90 config => $ config,137 config => $self, 91 138 irc => $irc, 92 139 global_context => $global_context, 93 140 }, 94 141 inline_states => { 95 _start => \&on_irc_start,96 _default => \&on_irc_default,97 98 irc_001 => \&on_irc_001,99 irc_join => \&on_irc_join,100 irc_part => \&on_irc_part,101 irc_public => \&on_irc_public,102 irc_notice => \&on_irc_notice,103 irc_topic => \&on_irc_topic,104 irc_332 => \&on_irc_topicraw,105 irc_ctcp_action => \&on_irc_ctcp_action,106 irc_kick => \&on_irc_kick,107 irc_snotice => \&on_irc_snotice,108 109 autoping => \&do_autoping,110 connect => \&do_connect,142 _start => \&on_irc_start, 143 _default => \&on_irc_default, 144 145 irc_001 => \&on_irc_001, 146 irc_join => \&on_irc_join, 147 irc_part => \&on_irc_part, 148 irc_public => \&on_irc_public, 149 irc_notice => \&on_irc_notice, 150 irc_topic => \&on_irc_topic, 151 irc_332 => \&on_irc_topicraw, 152 irc_ctcp_action => \&on_irc_ctcp_action, 153 irc_kick => \&on_irc_kick, 154 irc_snotice => \&on_irc_snotice, 155 156 autoping => \&do_autoping, 157 connect => \&do_connect, 111 158 112 159 irc_disconnected => \&on_irc_reconnect, … … 117 164 118 165 $global_context->add_channel( 119 App::Mobirc::Model::Channel->new($global_context, U('*server*')) 120 ); 121 } 166 App::Mobirc::Model::Channel->new( $global_context, U('*server*') ) ); 167 }; 122 168 123 169 # ------------------------------------------------------------------------- … … 144 190 DEBUG "CONNECTED"; 145 191 146 my $channel = $poe->heap->{global_context}->get_channel(decode( 'utf8', '*server*' )); 192 my $channel = 193 $poe->heap->{global_context}->get_channel( decode( 'utf8', '*server*' ) ); 147 194 $channel->add_message( 148 195 App::Mobirc::Model::Message->new( 149 196 who => undef, 150 body => decode( 'utf8', 'Connected to irc server!'),197 body => decode( 'utf8', 'Connected to irc server!' ), 151 198 class => 'connect', 152 199 ) … … 162 209 DEBUG "JOIN"; 163 210 164 my ( $who, $channel_name) = _get_args($poe);211 my ( $who, $channel_name ) = _get_args($poe); 165 212 166 213 $who =~ s/!.*//; … … 173 220 my $channel = $poe->heap->{global_context}->get_channel($channel_name); 174 221 unless ($channel) { 175 $channel = App::Mobirc::Model::Channel->new( 176 $poe->heap->{global_context}, 177 $channel_name, 178 ); 179 $poe->heap->{global_context}->add_channel( $channel ); 222 $channel = 223 App::Mobirc::Model::Channel->new( $poe->heap->{global_context}, 224 $channel_name, ); 225 $poe->heap->{global_context}->add_channel($channel); 180 226 } 181 227 … … 197 243 my $poe = sweet_args; 198 244 199 my ( $who, $channel_name, $msg) = _get_args($poe);245 my ( $who, $channel_name, $msg ) = _get_args($poe); 200 246 201 247 $who =~ s/!.*//; … … 233 279 DEBUG "IRC PUBLIC"; 234 280 235 my ( $who, $channel_name, $msg) = _get_args($poe);281 my ( $who, $channel_name, $msg ) = _get_args($poe); 236 282 237 283 $who =~ s/!.*//; … … 249 295 ); 250 296 my $irc = $poe->heap->{irc}; 297 251 298 if ( $who eq $irc->nick_name ) { 252 299 DEBUG "CLEAR UNREAD"; … … 261 308 my $poe = sweet_args; 262 309 263 my ( $who, $channel_name, $msg) = _get_args($poe);310 my ( $who, $channel_name, $msg ) = _get_args($poe); 264 311 265 312 DEBUG "IRC NOTICE $who $channel_name $msg"; 266 313 267 for my $code (@{ $poe->heap->{global_context}->get_hook_codes('on_irc_notice') }) { 268 my $finished = $code->($poe, $who, $channel_name, $msg); 269 return if $finished; 314 if ( $poe->heap->{global_context} 315 ->run_hook_first( 'on_irc_notice', $poe, $who, $channel_name, $msg ) ) 316 { 317 return; 270 318 } 271 319 … … 289 337 my $poe = sweet_args; 290 338 291 my ( $who, $channel_name, $topic) = _get_args($poe);339 my ( $who, $channel_name, $topic ) = _get_args($poe); 292 340 293 341 $who =~ s/!.*//; … … 306 354 ); 307 355 308 $poe->heap->{seen_traffic} = true;309 $poe->heap->{disconnect_msg} = true;356 $poe->heap->{seen_traffic} = true; 357 $poe->heap->{disconnect_msg} = true; 310 358 } 311 359 … … 313 361 my $poe = sweet_args; 314 362 315 my ( $x, $y, $dat) = _get_args($poe);363 my ( $x, $y, $dat ) = _get_args($poe); 316 364 317 365 my ( $channel, $topic ) = @{$dat}; … … 319 367 DEBUG "SET TOPIC RAW: $channel => $topic"; 320 368 321 $poe->heap->{global_context}->get_channel(normalize_channel_name($channel))->topic($topic); 322 $poe->heap->{seen_traffic} = true; 323 $poe->heap->{disconnect_msg} = true; 369 $poe->heap->{global_context} 370 ->get_channel( normalize_channel_name($channel) )->topic($topic); 371 $poe->heap->{seen_traffic} = true; 372 $poe->heap->{disconnect_msg} = true; 324 373 } 325 374 … … 327 376 my $poe = sweet_args; 328 377 329 my ( $who, $channel_name, $msg) = _get_args($poe);378 my ( $who, $channel_name, $msg ) = _get_args($poe); 330 379 331 380 $who =~ s/!.*//; … … 333 382 334 383 my $channel = $poe->heap->{global_context}->get_channel($channel_name); 335 my $body = sprintf( decode('utf8', "* %s %s"), $who, $msg);384 my $body = sprintf( decode( 'utf8', "* %s %s" ), $who, $msg ); 336 385 $channel->add_message( 337 386 App::Mobirc::Model::Message->new( … … 351 400 DEBUG "DNBKICK"; 352 401 353 my ( $kicker, $channel_name, $kickee, $msg) = _get_args($poe);402 my ( $kicker, $channel_name, $kickee, $msg ) = _get_args($poe); 354 403 $msg ||= 'Flooder'; 355 404 … … 377 426 my $poe = sweet_args; 378 427 379 $poe->kernel->post( mobirc_irc => time ) unless $poe->heap->{seen_traffic}; 428 $poe->kernel->post( mobirc_irc => time ) 429 unless $poe->heap->{seen_traffic}; 380 430 $poe->heap->{seen_traffic} = false; 381 431 $poe->kernel->delay( autoping => $poe->heap->{config}->{ping_delay} ); … … 385 435 my $poe = sweet_args; 386 436 387 my ( $message, ) = _get_args($poe);437 my ( $message, ) = _get_args($poe); 388 438 389 439 DEBUG "getting snotice : $message"; 390 440 391 my $channel = $poe->heap->{global_context}->get_channel( U('*server*' ));441 my $channel = $poe->heap->{global_context}->get_channel( U('*server*') ); 392 442 $channel->add_message( 393 443 App::Mobirc::Model::Message->new( … … 404 454 DEBUG "!RECONNECT! " . $poe->heap->{disconnect_msg}; 405 455 if ( $poe->heap->{disconnect_msg} ) { 406 my $channel = $poe->heap->{global_context}->get_channel(decode( 'utf8', '*server*' )); 456 my $channel = 457 $poe->heap->{global_context} 458 ->get_channel( decode( 'utf8', '*server*' ) ); 407 459 $channel->add_message( 408 460 App::Mobirc::Model::Message->new( 409 who => undef, 410 body => decode( 'utf8', 'Disconnected from irc server, trying to reconnect...'), 461 who => undef, 462 body => decode( 463 'utf8', 464 'Disconnected from irc server, trying to reconnect...' 465 ), 411 466 class => 'reconnect', 412 467 ) … … 422 477 423 478 my @ret; 424 for my $elem (@{$poe->args}) { 425 if ( ref $elem && ref $elem eq 'ARRAY') { 426 push @ret, [map { decode($poe->heap->{config}->{incode}, $_) } @$elem]; 427 } else { 428 push @ret, decode($poe->heap->{config}->{incode}, $elem); 479 for my $elem ( @{ $poe->args } ) { 480 if ( ref $elem && ref $elem eq 'ARRAY' ) { 481 push @ret, 482 [ map { decode( $poe->heap->{config}->{incode}, $_ ) } @$elem ]; 483 } 484 else { 485 push @ret, decode( $poe->heap->{config}->{incode}, $elem ); 429 486 } 430 487 } -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Component/Twitter.pm
r12148 r13013 1 1 package App::Mobirc::Plugin::Component::Twitter; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use POE::Component::Client::Twitter; 5 5 use App::Mobirc::Model::Channel; … … 9 9 use Encode; 10 10 11 sub register { 12 my ($class, $global_context, $conf) = @_; 11 has channel => ( 12 is => 'ro', 13 isa => 'Str', 14 default => U('#twitter'), 15 ); 13 16 14 DEBUG "register twitter client component"; 15 $global_context->register_hook( 16 'run_component' => sub { _init($conf, shift) }, 17 ); 18 $global_context->register_hook( 19 'process_command' => sub { my ($global_context, $command, $channel) = @_; _process_command($conf, $global_context, $command, $channel) }, 20 ); 17 has 'alias' => ( 18 is => 'ro', 19 isa => 'Str', 20 default => 'twitter', 21 ); 21 22 22 $conf->{channel} ||= U '#twitter'; 23 $conf->{alias} ||= 'twitter'; 24 $conf->{screenname} ||= $conf->{username}; 25 $conf->{friend_timeline_interval} ||= 60; 26 } 23 has screenname => ( 24 is => 'ro', 25 isa => 'Str', 26 lazy => 1, 27 default => { shift->username }, 28 ); 27 29 28 sub _process_command { 29 my ($conf, $global_context, $command, $channel) = @_; 30 has username => ( 31 is => 'ro', 32 isa => 'Str', 33 required => 1, 34 ); 30 35 31 if ($conf->{channel} eq $channel->name) { 32 $poe_kernel->post( $conf->{alias}, 'update', encode('utf-8', $command) ); 36 has password => ( 37 is => 'ro', 38 isa => 'Str', 39 required => 1, 40 ); 41 42 has friend_timeline_interval => ( 43 is => 'ro', 44 isa => 'Int', 45 default => 60, 46 ); 47 48 hook 'process_command' => sub { 49 my ($self, $global_context, $command, $channel) = @_; 50 51 if ($self->channel eq $channel->name) { 52 $poe_kernel->post( $self->alias, 'update', encode('utf-8', $command) ); 33 53 $channel->add_message( 34 54 App::Mobirc::Model::Message->new( 35 who => $conf->{screenname},55 who => $self->screenname, 36 56 body => $command, 37 57 class => 'public', … … 41 61 } 42 62 return false; 43 } 63 }; 44 64 45 sub _init{46 my ( $ conf,$global_context ) = @_;65 hook 'run_component' => sub { 66 my ( $sself $global_context ) = @_; 47 67 48 my $twitter = POE::Component::Client::Twitter->spawn( %{ $conf } ); 49 50 $global_context->add_channel( 51 App::Mobirc::Model::Channel->new( $global_context, $conf->{channel}, ), 52 ); 68 my $twitter = POE::Component::Client::Twitter->spawn( %{ $self } ); 53 69 54 70 POE::Session->create( … … 62 78 my $poe = sweet_args; 63 79 $twitter->yield('friend_timeline'); 64 $poe->kernel->delay( 'delay_friend_timeline' => $ conf->{friend_timeline_interval});80 $poe->kernel->delay( 'delay_friend_timeline' => $self->friend_timeline_interval ); 65 81 }, 66 82 'twitter.friend_timeline_success' => sub { 67 83 my $poe = sweet_args; 68 84 my $ret = $poe->args->[0] || []; 69 my $channel = $global_context->get_channel( $ conf->{channel});85 my $channel = $global_context->get_channel( $self->channel ); 70 86 DEBUG "twitter friend timeline SUCCESSS!!"; 71 87 DEBUG "got lines: " . scalar(@$ret); … … 76 92 DEBUG "GOT STATUS IS: $body($who)"; 77 93 78 next if $ conf->{screenname}eq $who;94 next if $self->screenname eq $who; 79 95 80 96 $channel->add_message( … … 89 105 } 90 106 ); 91 } 107 }; 92 108 93 109 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/DocRoot.pm
r12811 r13013 1 1 package App::Mobirc::Plugin::DocRoot; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use App::Mobirc::Util; 5 5 use XML::LibXML; 6 6 use Encode; 7 use Params::Validate ':all'; 7 8 8 sub register { 9 my ($class, $global_context, $conf) = @_; 9 has root => ( 10 is => 'ro', 11 isa => 'Str', 12 required => 1, 13 ); 10 14 11 DEBUG "Rewrite Document Root"; 15 hook request_filter => sub { 16 my ($self, $global_context, $c) = validate_pos(@_, 17 { isa => __PACKAGE__ }, 18 { isa => 'App::Mobirc' }, 19 { isa => 'HTTP::Engine::Context' }, 20 ); 12 21 13 $global_context->register_hook( 14 request_filter => sub { _request_filter($conf, @_) }, 15 ); 16 $global_context->register_hook( 17 response_filter => sub { _response_filter($conf, @_) }, 18 ); 19 $global_context->register_hook( 20 'html_filter' => sub { _html_filter_docroot($_[0], $_[1], $conf) }, 21 ); 22 } 23 24 sub _request_filter { 25 my ($conf, $c) = @_; 26 27 my $root = $conf->{root}; 22 my $root = $self->root; 28 23 $root =~ s!/$!!; 29 24 30 25 my $path = $c->req->uri->path; 31 DEBUG "BEFORE : " . $c->req->uri;32 26 $path =~ s!^$root!!; 33 27 $c->req->uri->path($path); 34 DEBUG "AFTER : " . $c->req->uri; 35 } 28 }; 36 29 37 sub _response_filter{38 my ($ conf, $c) = @_;30 hook response_filter => sub { 31 my ($self, $global_context, $c) = @_; 39 32 40 33 if ($c->res->redirect) { 41 34 DEBUG "REWRITE REDIRECT : " . $c->res->redirect; 42 35 43 my $root = $ conf->{root};36 my $root = $self->root; 44 37 $root =~ s!/$!!; 45 38 $c->res->redirect( $root . $c->res->redirect ); … … 47 40 DEBUG "FINISHED: " . $c->res->redirect; 48 41 } 49 } 42 }; 50 43 51 sub _html_filter_docroot{52 my ($ c, $content, $conf) = @_;44 hook html_filter => sub { 45 my ($self, $global_context, $c, $content, ) = @_; 53 46 54 47 DEBUG "FILTER DOCROOT"; 55 48 DEBUG "CONTENT IS UTF* : " . Encode::is_utf8($content); 56 49 57 my $root = $ conf->{root};50 my $root = $self->root; 58 51 $root =~ s!/$!!; 59 52 … … 89 82 $html =~ s{<!DOCTYPE[^>]*>\s*}{}; 90 83 91 decode($doc->encoding || "UTF-8", $html);92 } 84 return ($c, decode($doc->encoding || "UTF-8", $html)); 85 }; 93 86 94 87 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/GPS.pm
r12863 r13013 1 1 package App::Mobirc::Plugin::GPS; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use HTTP::MobileAgent; 5 5 use HTTP::MobileAgent::Plugin::Locator; … … 11 11 use UNIVERSAL::require; 12 12 use String::TT ':all'; 13 use Encode::JP::Mobile; 13 14 14 sub register { 15 my ($class, $global_context, $conf) = @_; 15 has inv_geocoder => ( 16 is => 'ro', 17 isa => 'Str', 18 default => 'Null', 19 ); 16 20 17 $global_context->register_hook( 18 channel_page_option => sub { 19 my ($channel, $global_context) = @_; 21 hook channel_page_option => sub { 22 my ( $self, $global_context, $channel ) = @_; 20 23 21 my $time = time(); 22 return tt qq{<a href="/channel/[% channel.name | uri %]/gps?time=[% time | html %]">gps</a>}; 23 }, 24 ); 24 my $time = time(); 25 return tt qq{<a href="/channel/[% channel.name | uri %]/gps">gps</a>}; 26 }; 25 27 26 $global_context->register_hook( 27 httpd => sub { 28 my ($c, $uri) = @_; 28 hook httpd => sub { 29 my ( $self, $global_context, $c, $uri ) = @_; 29 30 30 if ($uri =~ m{^/channel/([^/]+)/gps$}) {31 my $channel_name = $1;31 if ( $uri =~ m{^/channel/([^/]+)/gps$} ) { 32 my $channel_name = $1; 32 33 33 my $config = App::Mobirc->context->config; 34 my $path = File::Spec->catfile($config->{global}->{assets_dir}, 'plugin', 'GPS', 'measure.tt2'); 34 my $config = App::Mobirc->context->config; 35 my $path = File::Spec->catfile( $config->{global}->{assets_dir}, 36 'plugin', 'GPS', 'measure.tt2' ); 35 37 36 local %ENV; 37 if (my $devcap_multimedia = $c->req->header('X-UP-DEVCAP-MULTIMEDIA')) { 38 $ENV{HTTP_X_UP_DEVCAP_MULTIMEDIA} = $devcap_multimedia; 39 } 38 local %ENV; 39 if ( my $devcap_multimedia = $c->req->header('X-UP-DEVCAP-MULTIMEDIA') ) 40 { 41 $ENV{HTTP_X_UP_DEVCAP_MULTIMEDIA} = $devcap_multimedia; 42 } 40 43 41 my $tt = Template->new(ABSOLUTE => 1);42 $tt->process(43 $path,44 {45 request => $c->request,46 req => $c->req,47 channel_name => $channel_name,48 mobile_agent => $c->req->mobile_agent,49 docroot => $config->{httpd}->{root},50 port => $config->{httpd}->{port},51 },52 \my $out53 ) or warn $tt->error;44 my $tt = Template->new( ABSOLUTE => 1 ); 45 $tt->process( 46 $path, 47 { 48 request => $c->request, 49 req => $c->req, 50 channel_name => $channel_name, 51 mobile_agent => $c->req->mobile_agent, 52 docroot => $config->{httpd}->{root}, 53 port => $config->{httpd}->{port}, 54 }, 55 \my $out 56 ) or warn $tt->error; 54 57 55 $c->res->content_type(encode('utf8', 'text/html; charset=Shift_JIS')); 56 $c->res->body($out); 57 return 1; 58 } else { 59 return 0; 60 } 61 }, 62 ); 58 $c->res->content_type( 59 encode( 'utf8', 'text/html; charset=Shift_JIS' ) ); 60 $c->res->body($out); 61 return 1; 62 } 63 else { 64 return 0; 65 } 66 }; 63 67 64 $global_context->register_hook( 65 httpd => sub { 66 my ($c, $uri) = @_; 68 hook httpd => sub { 69 my ($self, $global_context, $c, $uri) = @_; 67 70 68 if ($uri =~ m{^/channel/([^/]+)/gps_do$}) {69 my $channel_name = uri_unescape $1;70 my $inv_geocoder = $conf->{inv_geocoder} || 'EkiData';71 if ($uri =~ m{^/channel/([^/]+)/gps_do$}) { 72 my $channel_name = uri_unescape $1; 73 my $inv_geocoder = $self->inv_geocoder; 71 74 72 my $point = $c->req->mobile_agent->get_location( $c->req->query_params );75 my $point = $c->req->mobile_agent->get_location( $c->req->query_params ); 73 76 74 "App::Mobirc::Plugin::GPS::InvGeocoder::$inv_geocoder"->use or die $@;75 my $msg = "App::Mobirc::Plugin::GPS::InvGeocoder::$inv_geocoder"->inv_geocoder($point);76 $msg = uri_escape encode($c->req->mobile_agent->encoding, $msg);77 "App::Mobirc::Plugin::GPS::InvGeocoder::$inv_geocoder"->use or die $@; 78 my $msg = "App::Mobirc::Plugin::GPS::InvGeocoder::$inv_geocoder"->inv_geocoder($point); 79 $msg = uri_escape encode($c->req->mobile_agent->encoding, $msg); 77 80 78 my $time = time(); 79 my $redirect = tt "/channels/[% channel_name | uri %]?msg=L:[% msg %]&t=[% time | uri %]"; 80 $c->res->redirect($redirect); 81 return 1; 82 } else { 83 return 0; 84 } 85 }, 86 ); 87 } 81 my $redirect = tt "/channels/[% channel_name | uri %]?msg=L:[% msg %]"; 82 $c->res->redirect($redirect); 83 return 1; 84 } else { 85 return 0; 86 } 87 }; 88 88 89 89 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/HTMLFilter/CompressHTML.pm
r6129 r13013 2 2 # vim:expandtab: 3 3 use strict; 4 use warnings;4 use MooseX::Plaggerize::Plugin; 5 5 use App::Mobirc::Util; 6 6 7 sub register { 8 my ($class, $global_context) = @_; 9 10 $global_context->register_hook( 11 'html_filter' => \&_html_filter_compress 12 ); 13 } 14 15 sub _html_filter_compress { 16 my ($c, $content) = @_; 7 hook html_filter => sub { 8 my ($self, $global_context, $c, $content) = @_; 17 9 18 10 my $bsize = length $content; … … 30 22 DEBUG "Compress before->$bsize after->$asize $rate% packets->$packets"; 31 23 32 return $content; 33 } 34 35 24 return ( $c, $content); 25 }; 36 26 37 27 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/HTMLFilter/ConvertPictograms.pm
r12585 r13013 1 1 package App::Mobirc::Plugin::HTMLFilter::ConvertPictograms; 2 2 use strict; 3 use warnings; 4 use HTML::Entities::ConvertPictogramMobileJp; 3 use MooseX::Plaggerize::Plugin; 4 use HTML::Entities::ConvertPictogramMobileJp qw(convert_pictogram_entities); 5 use Params::Validate ':all'; 5 6 6 sub register { 7 my ($class, $global_context) = @_; 7 hook html_filter => sub { 8 my ($self, $global_context, $c, $content) = validate_pos(@_, 9 { isa => __PACKAGE__ }, 10 { isa => 'App::Mobirc' }, 11 { isa => 'HTTP::Engine::Context' }, 12 { type => SCALAR }, 13 ); 8 14 9 $global_context->register_hook( 10 'html_filter' => \&_html_convert_pictograms 15 return ( 16 $c, 17 convert_pictogram_entities( 18 mobile_agent => $c->req->mobile_agent, 19 html => $content, 20 ) 11 21 ); 12 } 13 14 sub _html_convert_pictograms { 15 my ($c, $content) = @_; 16 17 convert_pictogram_entities( 18 mobile_agent => $c->req->mobile_agent, 19 html => $content, 20 ); 21 } 22 }; 22 23 23 24 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/HTMLFilter/DoCoMoCSS.pm
r12866 r13013 1 1 package App::Mobirc::Plugin::HTMLFilter::DoCoMoCSS; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use CSS::Tiny; 5 5 use XML::LibXML; … … 8 8 use Encode; 9 9 10 sub register { 11 my ($class, $global_context) = @_; 12 13 DEBUG "Register DoCoMoCSS"; 14 15 $global_context->register_hook( 16 'html_filter' => \&_html_filter_docomocss, 17 ); 18 } 19 20 # based from HTML::DoCoMoCSS 21 sub _html_filter_docomocss { 22 my $c = shift; 23 my $content = shift; 10 # some code copied from HTML::DoCoMoCSS 11 hook 'html_filter' => sub { 12 my ($self, $global_context, $c, $content) = @_; 24 13 25 14 DEBUG "FILTER DOCOMO CSS"; 26 return $contentunless $c->req->mobile_agent->is_docomo;15 return ($c, $content) unless $c->req->mobile_agent->is_docomo; 27 16 28 17 # escape Numeric character reference. … … 52 41 $content =~ s{(<a[^>]+)/>}{$1></a>}gi; 53 42 54 return $pict_unescape->();55 } 43 return ($c, $pict_unescape->()); 44 }; 56 45 57 46 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/HTMLFilter/StickyTime.pm
r12884 r13013 1 1 package App::Mobirc::Plugin::HTMLFilter::StickyTime; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 use App::Mobirc::Util; 5 5 use HTML::StickyQuery; 6 6 7 sub register { 8 my ($class, $global_context) = @_; 9 10 $global_context->register_hook( 11 'html_filter' => \&_html_filter 12 ); 13 $global_context->register_hook( 14 response_filter => sub { _response_filter(@_) }, 15 ); 16 } 17 18 sub _response_filter { 19 my ($c, ) = @_; 7 hook response_filter => sub { 8 my ($self, $global_context, $c) = @_; 20 9 21 10 if ($c->res->redirect) { … … 24 13 return $c->res->redirect( $uri->as_string ); 25 14 } 26 } 15 }; 27 16 28 29 sub _html_filter { 30 my ($c, $content) = @_; 17 hook html_filter => sub { 18 my ($self, $global_context, $c, $content) = @_; 31 19 32 20 my $sticky = HTML::StickyQuery->new(); 33 return $sticky->sticky( 34 scalarref => \$content, 35 param => { t => time() }, 21 22 return ( 23 $c, 24 $sticky->sticky( 25 scalarref => \$content, 26 param => { t => time() }, 27 ) 36 28 ); 37 } 38 39 29 }; 40 30 41 31 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/IRCCommand/TiarraLog.pm
r5980 r13013 1 # vim:expandtab:2 1 package App::Mobirc::Plugin::IRCCommand::TiarraLog; 3 2 use strict; 4 use warnings;3 use MooseX::Plaggerize::Plugin; 5 4 use Encode; 6 5 use App::Mobirc::Util; 7 6 8 sub register { 9 my ($class, $global_context, $conf) = @_; 7 has sysmsg_prefix => ( 8 is => 'ro', 9 isa => 'Str', 10 default => 'tiarra', 11 ); 10 12 11 $global_context->register_hook( 12 'on_irc_notice' => sub { _process(@_, $conf) }, 13 ); 14 15 $conf->{sysmsg_prefix} ||= q{tiarra}; 16 } 17 18 sub _process { 19 my ($poe, $who, $channel, $msg, $conf) = @_; 20 13 hook on_irc_notice => sub { 14 my ($self, $global_context, $poe, $who, $channel, $msg) = @_; 21 15 22 16 # Tiarra Log::Recent Parser 23 if ($who && $who eq $ conf->{sysmsg_prefix}) {17 if ($who && $who eq $self->sysmsg_prefix) { 24 18 # header: %H:%M:%S 25 19 # header: %H:%M … … 84 78 85 79 return false; 86 } 80 }; 87 81 88 82 1; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/MessageBodyFilter/Clickable.pm
r6757 r13013 2 2 # vim:expandtab: 3 3 use strict; 4 use warnings;4 use MooseX::Plaggerize::Plugin; 5 5 use URI::Find; 6 6 use URI::Escape; … … 9 9 @URI::tel::ISA = qw( URI ); 10 10 11 sub register { 12 my ($class, $global_context, $conf) = @_; 11 has accept_schemes => ( 12 is => 'ro', 13 isa => 'ArrayRef', 14 ); 13 15 14 $global_context->register_hook(15 'message_body_filter' => sub { my $body = shift; process($body, $conf) },16 );17 } 16 has http_link_string => ( 17 is => 'ro', 18 isa => 'Str', 19 ); 18 20 19 sub process { 20 my ( $text, $conf ) = @_; 21 has redirector => ( 22 is => 'ro', 23 isa => 'Str', 24 ); 21 25 22 my $as = $conf->{accept_schemes}; 26 has au_pcsv => ( 27 is => 'ro', 28 isa => 'Bool', 29 ); 30 31 has pocket_hatena => ( 32 is => 'ro', 33 isa => 'Bool', 34 ); 35 36 has google_gwt => ( 37 is => 'ro', 38 isa => 'Bool', 39 ); 40 41 hook message_body_filter => sub { 42 my ( $self, $global_context, $text ) = @_; 43 44 my $as = $self->accept_schemes; 23 45 24 46 my $link_string_table = {}; … … 42 64 sub { 43 65 my ( $uri, $orig_uri ) = @_; 44 if ($ conf->{accept_schemes}&&66 if ($self->accept_schemes && 45 67 !(grep { $_ eq $uri->scheme } @$as)) { 46 68 return $orig_uri; 47 69 } 48 return (__PACKAGE__->can("process_" . $uri->scheme) || 49 \&process_default)->($conf, $uri, $orig_uri, $link_string_table); 70 return ($self->can("process_" . $uri->scheme) || \&process_default)->($self, $uri, $orig_uri, $link_string_table); 50 71 } 51 72 )->find( \$text ); 52 73 53 74 return $text; 54 } 75 }; 55 76 56 77 sub process_http { 57 my ( $ conf, $uri, $orig_uri ) = @_;78 my ( $self, $uri, $orig_uri ) = @_; 58 79 my $out = ""; 59 80 my $link_string = $orig_uri; 60 81 61 if ( $ conf->{http_link_string}) {62 $link_string =$ conf->{http_link_string};82 if ( $self->http_link_string ) { 83 $link_string =$self->http_link_string; 63 84 $link_string =~ s{\$(\w+)}{ 64 85 $uri->$1; … … 69 90 my $encoded_uri = encode_entities($uri, q(<>&")); 70 91 71 if ( $ conf->{redirector}) {92 if ( $self->redirector ) { 72 93 $out = 73 94 sprintf( 74 95 '<a href="%s%s" rel="nofollow" class="url">%s</a>', 75 encode_entities($ conf->{redirector}, q(<>&")),96 encode_entities($self->redirector, q(<>&")), 76 97 $encoded_uri, 77 98 $link_string ); … … 79 100 $out = qq{<a href="$encoded_uri" rel="nofollow" class="url">$link_string</a>}; 80 101 } 81 if ( $ conf->{au_pcsv}) {102 if ( $self->au_pcsv ) { 82 103 $out .= qq{<a href="device:pcsiteviewer?url=$encoded_uri" rel="nofollow" class="au_pcsv">[PCSV]</a>}; 83 104 } 84 if ( $ conf->{pocket_hatena}) {105 if ( $self->pocket_hatena ) { 85 106 $out .= 86 107 sprintf( … … 88 109 uri_escape($uri) ); 89 110 } 90 if ( $ conf->{google_gwt}) {111 if ( $self->google_gwt ) { 91 112 $out .= 92 113 sprintf( … … 98 119 99 120 sub process_default { 100 my ( $ conf, $uri, $orig_uri, $link_string_table ) = @_;121 my ( $self, $uri, $orig_uri, $link_string_table ) = @_; 101 122 102 123 my $link_string = $orig_uri; -
lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/MessageBodyFilter/IRCColor.pm
r5980 r13013 1 1 package App::Mobirc::Plugin::MessageBodyFilter::IRCColor; 2 2 use strict; 3 use warnings;3 use MooseX::Plaggerize::Plugin; 4 4 5 sub register { 6 my ($class, $global_context, $conf) = @_; 5 has no_decorate => ( 6 is => 'ro', 7 isa => 'Bool', 8 default => 0, 9 ); 7 10 8 $global_context->register_hook( 9 'message_body_filter' => sub { my $body = shift; process($body, $conf) }, 10 ); 11 } 11 hook message_body_filter => sub { 12 my ( $self, $global_context, $text ) = @_; 12 13 13 sub process { 14 my ( $text, $conf ) = @_; 15 16 return _decorate_irc_color($text, $conf->{no_decorate} || 0); 17 } 14 return _decorate_irc_color($text, $self->no_decorate); 15 }; 18 16 19 17 sub _decorate_irc_color { … … 21 19 22 20 if ( $src !~ /[\x02\x03\x0f\x16\x1f]/ ) { 23 24 21 # skip without colorcode 25 22 return $src; -
lang/perl/mobirc/trunk/t/HTTPD/Template/IRCMessage.t
r12638 r13013 14 14 plugin => [ 15 15 { 16 module => 'App::Mobirc::Plugin::Component::IRCClient', 17 config => 18 { groups => { initialJ => [qw(jknaoya jkondo jagayam)] }, }, 16 module => 'Component::IRCClient', 17 config => { 18 groups => { initialJ => [qw(jknaoya jkondo jagayam)] }, 19 nick => 'foo', 20 port => 3333, 21 server => '127.0.0.1', 22 }, 19 23 }, 20 24 ] -
lang/perl/mobirc/trunk/t/Plugins/Component/IRCClient.t
r5980 r13013 16 16 17 17 my $config = { 18 plugin => [19 {20 module => 'App::Mobirc::Plugin::Component::IRCClient',21 config => {22 nick => 'testee',23 port => $PORT,24 incode => 'utf8',25 username => 'test man',26 desc => 'hoge',27 server => 'localhost',28 },29 }30 ],31 18 httpd => { 32 19 port => 88888, … … 38 25 39 26 my $global_context = App::Mobirc->new($config); 40 $_->($global_context) for @{$global_context->get_hook_codes('run_component')}; 27 $global_context->load_plugin( 28 { 29 module => 'Component::IRCClient', 30 config => { 31 nick => 'testee', 32 port => $PORT, 33 incode => 'utf8', 34 username => 'test man', 35 desc => 'hoge', 36 server => 'localhost', 37 }, 38 } 39 ); 40 $global_context->run_hook('run_component'); 41 41 POE::Session->create( 42 42 package_states => [ -
lang/perl/mobirc/trunk/t/Plugins/DocRoot.t
r7817 r13013 2 2 use warnings; 3 3 use utf8; 4 use App::Mobirc ::Plugin::DocRoot;4 use App::Mobirc; 5 5 use Encode; 6 6 use Test::Base; 7 8 my $global_context = App::Mobirc->new( 9 { 10 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 11 global => { keywords => [qw/foo/] } 12 } 13 ); 14 $global_context->load_plugin( {module => 'DocRoot', config => {root => '/foo/'}} ); 7 15 8 16 filters { … … 12 20 sub convert { 13 21 my $src = shift; 22 my $c = undef; 14 23 ok Encode::is_utf8($src); 15 my $dst = App::Mobirc::Plugin::DocRoot::_html_filter_docroot(undef, $src, {root => '/foo/'});16 ok Encode::is_utf8($ dst);17 $ dst;24 my ($cdst, $htmldst, ) = $global_context->run_hook_filter( 'html_filter', $c, $src ); 25 ok Encode::is_utf8($htmldst); 26 $htmldst; 18 27 } 19 28 -
lang/perl/mobirc/trunk/t/Plugins/Filter/clickable.t
r6757 r13013 2 2 use warnings; 3 3 use Test::Base; 4 use App::Mobirc ::Plugin::MessageBodyFilter::Clickable;4 use App::Mobirc; 5 5 6 6 plan tests => 1*blocks; … … 12 12 sub clickable { 13 13 my $x = shift; 14 App::Mobirc::Plugin::MessageBodyFilter::Clickable::process( $x->{text}, $x->{conf} ); 14 my $global_context = App::Mobirc->new( 15 { 16 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 17 global => { keywords => [qw/foo/] } 18 } 19 ); 20 $global_context->load_plugin( { module => 'MessageBodyFilter::Clickable', config => $x->{conf} } ); 21 my ($res, ) = $global_context->run_hook_filter('message_body_filter', $x->{text}); 22 $res; 15 23 } 16 24 … … 79 87 text: http://d.hatena.ne.jp/ 80 88 conf: 81 pocket_hatena: true89 pocket_hatena: 1 82 90 --- expected: <a href="http://d.hatena.ne.jp/" rel="nofollow" class="url">http://d.hatena.ne.jp/</a><a href="http://mgw.hatena.ne.jp/?url=http%3A%2F%2Fd.hatena.ne.jp%2F;noimage=0;split=1" rel="nofollow" class="pocket_hatena">[ph]</a> 83 91 … … 86 94 text: http://d.hatena.ne.jp/ 87 95 conf: 88 au_pcsv: true96 au_pcsv: 1 89 97 --- expected: <a href="http://d.hatena.ne.jp/" rel="nofollow" class="url">http://d.hatena.ne.jp/</a><a href="device:pcsiteviewer?url=http://d.hatena.ne.jp/" rel="nofollow" class="au_pcsv">[PCSV]</a> 90 98 … … 93 101 text: http://www.google.co.jp/search?hl=ja&q=foo 94 102 conf: 95 au_pcsv: true103 au_pcsv: 1 96 104 --- expected: <a href="http://www.google.co.jp/search?hl=ja&q=foo" rel="nofollow" class="url">http://www.google.co.jp/search?hl=ja&q=foo</a><a href="device:pcsiteviewer?url=http://www.google.co.jp/search?hl=ja&q=foo" rel="nofollow" class="au_pcsv">[PCSV]</a> 97 105 … … 100 108 text: http://d.hatena.ne.jp/ 101 109 conf: 102 google_gwt: true110 google_gwt: 1 103 111 --- expected: <a href="http://d.hatena.ne.jp/" rel="nofollow" class="url">http://d.hatena.ne.jp/</a><a href="http://www.google.co.jp/gwt/n?u=http%3A%2F%2Fd.hatena.ne.jp%2F;_gwt_noimg=0" rel="nofollow" class="google_gwt">[gwt]</a> 104 112 -
lang/perl/mobirc/trunk/t/Plugins/Filter/decorate-irc-color.t
r6797 r13013 2 2 use warnings; 3 3 use Data::Dumper; 4 use App::Mobirc ::Plugin::MessageBodyFilter::IRCColor;4 use App::Mobirc; 5 5 6 6 use Test::Base; 7 7 eval q{ use String::IRC }; 8 8 plan skip_all => "String::IRC is not installed." if $@; 9 10 my $global_context = App::Mobirc->new( 11 { 12 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 13 global => { keywords => [qw/foo/] } 14 } 15 ); 16 $global_context->load_plugin( { module => 'MessageBodyFilter::IRCColor', config => { no_decorate => 0} } ); 9 17 10 18 filters { … … 14 22 sub decorate_irc_color { 15 23 my $x = shift; 16 App::Mobirc::Plugin::MessageBodyFilter::IRCColor::process( $x, {} ); 24 ($x,) = $global_context->run_hook_filter('message_body_filter', $x); 25 return $x; 17 26 } 18 27 -
lang/perl/mobirc/trunk/t/Plugins/Filter/no-decorate-irc-color.t
r6130 r13013 1 1 use strict; 2 2 use warnings; 3 use Data::Dumper; 4 use App::Mobirc::Plugin::MessageBodyFilter::IRCColor; 3 use App::Mobirc; 5 4 6 5 use Test::Base; 7 6 eval q{ use String::IRC }; 8 7 plan skip_all => "String::IRC is not installed." if $@; 8 9 my $global_context = App::Mobirc->new( 10 { 11 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 12 global => { keywords => [qw/foo/] } 13 } 14 ); 15 $global_context->load_plugin( { module => 'MessageBodyFilter::IRCColor', config => { no_decorate => 1} } ); 9 16 10 17 filters { … … 14 21 sub decorate_irc_color { 15 22 my $x = shift; 16 App::Mobirc::Plugin::MessageBodyFilter::IRCColor::process( $x, {no_decorate => 1} ); 23 ($x,) = $global_context->run_hook_filter('message_body_filter', $x); 24 return $x; 17 25 } 18 26 -
lang/perl/mobirc/trunk/t/Plugins/HTMLFilter/CompressHTML.t
r6134 r13013 3 3 use App::Mobirc::Plugin::HTMLFilter::CompressHTML; 4 4 use Test::Base; 5 use App::Mobirc; 6 7 my $global_context = App::Mobirc->new( 8 { 9 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 10 global => { keywords => [qw/foo/] } 11 } 12 ); 13 $global_context->load_plugin( 'HTMLFilter::CompressHTML' ); 5 14 6 15 filters { … … 8 17 }; 9 18 19 run_is input => 'expected'; 20 10 21 sub compress { 11 App::Mobirc::Plugin::HTMLFilter::CompressHTML::_html_filter_compress(undef, shift); 22 my $html = shift; 23 my $c = undef; 24 ($c, $html) = $global_context->run_hook_filter('html_filter', $c, $html); 25 $html; 12 26 } 13 27 -
lang/perl/mobirc/trunk/t/Plugins/HTMLFilter/ConvertPictograms.t
r12636 r13013 1 1 use strict; 2 2 use warnings; 3 use App::Mobirc ::Plugin::HTMLFilter::ConvertPictograms;3 use App::Mobirc; 4 4 use HTTP::MobileAgent; 5 use HTTP::Engine::Context; 5 6 use Test::Base; 6 7 7 { 8 package DummyContext; 9 sub new { 10 my ($class, $agent) = @_; 11 bless { agent => $agent }, $class; 8 my $global_context = App::Mobirc->new( 9 { 10 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 11 global => { keywords => [qw/foo/] } 12 12 } 13 sub req { 14 my $self = shift; 15 bless { %$self }, 'DummyContext'; 16 } 17 sub mobile_agent { shift->{agent} } 18 } 13 ); 14 $global_context->load_plugin( 'HTMLFilter::ConvertPictograms' ); 19 15 20 16 filters { … … 24 20 sub convert { 25 21 my $x = shift; 26 my $agent = HTTP::MobileAgent->new($x->{ua}); 27 App::Mobirc::Plugin::HTMLFilter::ConvertPictograms::_html_convert_pictograms( 28 DummyContext->new($agent), $x->{src} ); 22 my $c = HTTP::Engine::Context->new; 23 $c->req->user_agent( $x->{ua} ); 24 ($c, $x->{src}) = $global_context->run_hook_filter( 'html_filter', $c, $x->{src} ); 25 return $x->{src}; 29 26 } 30 27 -
lang/perl/mobirc/trunk/t/Plugins/HTMLFilter/DoCoMoCSS.t
r12886 r13013 1 1 use strict; 2 2 use warnings; 3 use Test::More tests => 3;3 use Test::More tests => 1; 4 4 use HTTP::MobileAgent; 5 5 use App::Mobirc; … … 11 11 my $global_context = App::Mobirc->new( 12 12 { 13 httpd => { port => 3333, title => 'mobirc', lines => 40},13 httpd => { port => 3333, }, 14 14 global => { keywords => [qw/foo/] } 15 15 } 16 16 ); 17 App::Mobirc::Plugin::HTMLFilter::DoCoMoCSS->register( 18 $global_context 19 ); 20 is scalar(@{$global_context->get_hook_codes('html_filter')}), 1; 21 my $code = $global_context->get_hook_codes('html_filter')->[0]; 22 is ref($code), 'CODE'; 17 $global_context->load_plugin('HTMLFilter::DoCoMoCSS'); 23 18 24 my $ src= <<'...';19 my $got = <<'...'; 25 20 <style type="text/css"> 26 21 a { … … 30 25 <a href="/">foo</a> 31 26 ... 27 ($c, $got) = $global_context->run_hook_filter('html_filter', $c, $got); 32 28 33 my $ dst= <<'...';29 my $expected = <<'...'; 34 30 <?xml version="1.0"?> 35 31 <a href="/" style="color:red;">foo</a> 36 32 ... 37 33 38 is $ code->($c, $src), $dst;34 is $got, $expected; 39 35 36 -
lang/perl/mobirc/trunk/t/Plugins/HTMLFilter/StickyTime.t
r12649 r13013 3 3 use App::Mobirc::Plugin::HTMLFilter::StickyTime; 4 4 use Test::Base; 5 use App::Mobirc; 6 7 my $global_context = App::Mobirc->new( 8 { 9 httpd => { port => 3333, title => 'mobirc', lines => 40 }, 10 global => { keywords => [qw/foo/] } 11 } 12 ); 13 $global_context->load_plugin( 'HTMLFilter::StickyTime' ); 5 14 6 15 plan tests => 1*blocks; 7 16 8 17 filters { 9 input => [qw/ compress/],18 input => [qw/sticky/], 10 19 expected => [qw/eval/], 11 20 }; … … 16 25 }; 17 26 18 sub compress { 19 App::Mobirc::Plugin::HTMLFilter::StickyTime::_html_filter(undef, shift); 27 sub sticky { 28 my $html = shift; 29 my $c = undef; 30 ($c, $html) = $global_context->run_hook_filter('html_filter', $c, $html); 31 return $html; 20 32 } 21 33
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)