| 1 | package HTML::MobileJp::Filter; | ||||||||||
| 2 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | our $VERSION = '0.01_03'; | |||||||||
| 4 | |||||||||||
| 5 | has filters => ( | ||||||||||
| 6 | is => 'rw', | ||||||||||
| 7 | isa => 'ArrayRef', | ||||||||||
| 8 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 9 | 5 | ); | |||||||||
| 10 | |||||||||||
| 11 | has stash => ( | ||||||||||
| 12 | is => 'rw', | ||||||||||
| 13 | isa => 'HashRef', | ||||||||||
| 14 | 3 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ); | |||||||||
| 16 | |||||||||||
| 17 | 5 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||
| 19 | |||||||||||
| 20 | 5 | ▶ | use Class::Trigger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 5 | ▶ | use Class::MOP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 5 | ▶ | use HTML::MobileJp::Filter::Content; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | sub new { | ||||||||||
| 25 | 3 | ▶ | my $self = shift->SUPER::new(@_); | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 26 | |||||||||||
| 27 | 3 | for my $config (@{ $self->filters }) { | |||||||||
| 28 | 5 | my $filter = do { | |||||||||
| 29 | 5 | ▶ | my $module = $config->{module} =~ m{^\+(.*)$} ? $1 : __PACKAGE__ ."::$config->{module}"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 5 | Class::MOP::load_class($module); | |||||||||
| 31 | 5 | $module->new($config); | |||||||||
| 32 | }; | ||||||||||
| 33 | |||||||||||
| 34 | $self->add_trigger(filter_process => sub { | ||||||||||
| 35 | 5 | ▶ | my $context = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 36 | 5 | $filter->mobile_agent($context->stash->{mobile_agent}); | |||||||||
| 37 | |||||||||||
| 38 | 5 | my $ret = $filter->filter($context->stash->{content}); | |||||||||
| 39 | 5 | ▶ | if (defined $ret) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 5 | $context->stash->{content}->update($ret); | |||||||||
| 41 | } | ||||||||||
| 42 | 5 | }); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 3 | $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub filter { | ||||||||||
| 49 | 3 | ▶ | my ($self, %param) = @_; | ||||||||
|
Subroutine
filter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | |||||||||||
| 51 | $self->stash({ | ||||||||||
| 52 | mobile_agent => $param{mobile_agent}, | ||||||||||
| 53 | 3 | content => HTML::MobileJp::Filter::Content->new(html => $param{html}), | |||||||||
| 54 | }); | ||||||||||
| 55 | |||||||||||
| 56 | 3 | $self->call_trigger('filter_process'); | |||||||||
| 57 | |||||||||||
| 58 | 3 | $self->stash->{content}->as_html; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 5 | 1; | |||||||||
| 62 | __END__ | ||||||||||
| 63 | |||||||||||
| 64 | =encoding utf-8 | ||||||||||
| 65 | |||||||||||
| 66 | =head1 NAME | ||||||||||
| 67 | |||||||||||
| 68 | HTML::MobileJp::Filter - Glue of modules for fighting with Japanese mobile web | ||||||||||
| 69 | |||||||||||
| 70 | =head1 SYNOPSIS | ||||||||||
| 71 | |||||||||||
| 72 | use HTML::MobileJp::Filter; | ||||||||||
| 73 | use HTTP::MobileAgent; | ||||||||||
| 74 | use YAML; | ||||||||||
| 75 | |||||||||||
| 76 | my $filter = HTML::MobileJp::Filter->new(YAML::Load <<'...' | ||||||||||
| 77 | --- | ||||||||||
| 78 | filters: | ||||||||||
| 79 | - module: DoCoMoCSS | ||||||||||
| 80 | config: | ||||||||||
| 81 | base_dir: /path/to/htdocs | ||||||||||
| 82 | - module: DoCoMoGUID | ||||||||||
| 83 | - module: FallbackImage | ||||||||||
| 84 | config: | ||||||||||
| 85 | template: '<img src="%s.gif" />' | ||||||||||
| 86 | params: | ||||||||||
| 87 | - unicode_hex | ||||||||||
| 88 | - module: +MyApp::Filter::Foo | ||||||||||
| 89 | ... | ||||||||||
| 90 | ); | ||||||||||
| 91 | |||||||||||
| 92 | $html = $filter->filter( | ||||||||||
| 93 | mobile_agent => HTTP::MobileAgent->new, | ||||||||||
| 94 | html => $html, | ||||||||||
| 95 | ); | ||||||||||
| 96 | |||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||
| 98 | |||||||||||
| 99 | HTML::MobileJp::Filter is 偉大な先人たちがつくってくれた携帯サイトに役立つ | ||||||||||
| 100 | CPAN モジュールたちをつなげる薄いフレームワークです。 | ||||||||||
| 101 | |||||||||||
| 102 | B<CAUTION: This module is still alpha, its possible the API will change!> | ||||||||||
| 103 | |||||||||||
| 104 | =head1 METHODS | ||||||||||
| 105 | |||||||||||
| 106 | =over 4 | ||||||||||
| 107 | |||||||||||
| 108 | =item new( filters => [ ] ) | ||||||||||
| 109 | |||||||||||
| 110 | =item filter( mobile_agent => $ua, html => $html ) | ||||||||||
| 111 | |||||||||||
| 112 | =back | ||||||||||
| 113 | |||||||||||
| 114 | =head1 SEE ALSO | ||||||||||
| 115 | |||||||||||
| 116 | L<http://search.cpan.org/search?mode=module&query=HTML::MobileJp::Filter::> | ||||||||||
| 117 | |||||||||||
| 118 | =head1 AUTHOR | ||||||||||
| 119 | |||||||||||
| 120 | Naoki Tomita E<lt>tomita@cpan.orgE<gt> | ||||||||||
| 121 | |||||||||||
| 122 | =head1 DEVELOPMENT | ||||||||||
| 123 | |||||||||||
| 124 | L<http://coderepos.org/share/browser/lang/perl/HTML-MobileJp-Filter> | ||||||||||
| 125 | |||||||||||
| 126 | #mobilejp on irc.freenode.net (I've joined as "tomi-ru") | ||||||||||
| 127 | |||||||||||
| 128 | =head1 LICENSE | ||||||||||
| 129 | |||||||||||
| 130 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 131 | it under the same terms as Perl itself. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||