Show
Ignore:
Timestamp:
06/26/08 07:29:09 (5 years ago)
Author:
tomi-ru
Message:

プラグインでは$cを意識しないようにした方がシンプルなのでMooseX::Plaggerizeつかうのやめた

Location:
lang/perl/HTML-MobileJp-Filter/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTML-MobileJp-Filter/trunk/Makefile.PL

    r14620 r14622  
    44all_from 'lib/HTML/MobileJp/Filter.pm'; 
    55 
    6 requires 'Foo::Bar'; 
     6requires 'Class::Trigger'; 
     7requires 'UNIVERSAL::require'; 
     8requires 'HTTP::MobileAgent'; 
     9 
     10requires 'Encode'; 
     11requires 'Encode::JP::Mobile'; 
     12requires 'HTML::DoCoMoCSS'; 
     13requires 'HTML::StickyQuery::DoCoMoGUID'; 
     14requires 'HTML::Entities::ConvertPictogramMobileJp'; 
    715 
    816build_requires 'Test::More'; 
    917 
     18use_test_base; 
    1019auto_include; 
    1120 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter.pm

    r14597 r14622  
    22use strict; 
    33use warnings; 
     4our $VERSION = '0.01'; 
    45 
    56use Carp; 
     
    78use UNIVERSAL::require; 
    89 
    9 use base 'Class::Accessor::Fast'; 
    10 __PACKAGE__->mk_accessors(qw( filters mobile_agent html )); 
    11  
    1210sub new { 
    1311    my ($class, %config) = @_; 
    14     my $self = $class->SUPER::new(\%config); 
     12    my $self = bless \%config, $class; 
    1513     
    16     for my $plugin (@{ $self->filters || [] }) { 
    17         my $module = __PACKAGE__ .'::'. delete $plugin->{module}; 
     14    for my $filter (@{ $self->{filters} || [] }) { 
     15        my $module = __PACKAGE__ .'::'. $filter->{module}; 
    1816        $module->require or croak $@; 
    19         $module->new($self, $plugin); 
     17        $module->new($self, $filter); 
    2018    } 
    2119     
    22     $self;  
     20    $self; 
    2321} 
    2422 
     
    2624    my ($self, %option) = @_; 
    2725     
    28     $self->html(""); 
    29     $self->{$_} = delete $option{$_} for keys %option; 
     26    $self->{$_} = $option{$_} for keys %option; 
    3027     
    31     $self->call_trigger('filter', $self); 
     28    $self->call_trigger('filter_process'); 
    3229     
    33     $self->html; 
     30    $self->{html}; 
    3431} 
    3532 
    36331; 
     34__END__ 
     35 
     36=encoding utf-8 
     37 
     38=head1 NAME 
     39 
     40HTML::MobileJp::Filter - Glue module for fighting Japanese mobile web 
     41 
     42=head1 SYNOPSIS 
     43 
     44  use HTML::MobileJp::Filter; 
     45  use HTTP::MobileAgent; 
     46  use YAML; 
     47 
     48  my $filter = HTML::MobileJp::Filter->new(YAML::Load <<'...' 
     49  --- 
     50  filters: 
     51    - module: DoCoMoCSS 
     52      config: 
     53        base_dir: root 
     54    - module: DoCoMoGUID 
     55    - module: FallbackImage 
     56      config: 
     57        template: '<img src="%s.gif" />' 
     58        params: 
     59          - unicode_hex 
     60  ... 
     61  ); 
     62 
     63  $html = $filter->filter( 
     64      mobile_agent => HTTP::MobileAgent->new, 
     65      html         => $html, 
     66  ); 
     67 
     68=head1 DESCRIPTION 
     69 
     70HTML::MobileJp::Filter is 
     71 
     72B<Note:> This module is still alpha, its possible the API will change. 
     73 
     74ご意見募集中です! 
     75 
     76=head1 METHODS 
     77 
     78=over 4 
     79 
     80=item new( filters => [ ] ) 
     81 
     82=item filter( mobile_agent => $ua, html => $html ) 
     83 
     84=back 
     85 
     86=head1 AUTHOR 
     87 
     88Naoki Tomita E<lt>tomita@cpan.orgE<gt> 
     89 
     90=head1 DEVELOPMENT 
     91 
     92L<http://coderepos.org/share/browser/lang/perl/HTML-MobileJp-Filter> 
     93 
     94#mobilejp on irc.freenode.net (I've joined as "tomi-ru") 
     95 
     96=head1 LICENSE 
     97 
     98This library is free software; you can redistribute it and/or modify 
     99it under the same terms as Perl itself. 
     100 
     101=head1 SEE ALSO 
     102 
     103 
     104=cut 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter/Base.pm

    r14597 r14622  
    44 
    55use base 'Class::Accessor::Fast'; 
    6 __PACKAGE__->mk_accessors(qw( config )); 
     6__PACKAGE__->mk_accessors(qw( mobile_agent config )); 
    77 
    88sub new { 
    9     my ($class, $provider, $config) = @_; 
     9    my ($class, $c, $config) = @_; 
    1010    my $self = $class->SUPER::new($config); 
    11       
    12     $provider->add_trigger(filter => sub { 
    13         $self->filter(@_); 
     11       
     12    $c->add_trigger(filter_process => sub { 
     13        my $c = shift; 
     14         
     15        $self->mobile_agent($c->{mobile_agent}); 
     16         
     17        my $ret = $self->filter($c->{html}); 
     18         
     19        $c->{html} = $ret if defined $ret; 
    1420    }); 
    1521     
     
    1723} 
    1824 
     25sub filter { } 
     26 
    19271; 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter/DoCoMoCSS.pm

    r14597 r14622  
    88 
    99sub filter { 
    10     my ($self, $filter) = @_; 
     10    my ($self, $html) = @_; 
    1111     
    12     unless ($filter->mobile_agent->is_docomo) { 
     12    unless ($self->mobile_agent->is_docomo) { 
    1313        return; 
    1414    } 
    1515     
    1616    my $inliner = HTML::DoCoMoCSS->new(base_dir => $self->config->{base_dir}); 
    17      
    18     my $html = $filter->html; 
    19      
    2017    $html = $inliner->apply($html); 
    21     $html = decode_utf8($html); 
    22      
    23     $filter->html($html); 
     18    $html = Encode::decode_utf8($html); 
    2419} 
    2520 
    26  
    27211; 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter/DoCoMoGUID.pm

    r14597 r14622  
    77 
    88sub filter { 
    9     my ($self, $filter) = @_; 
     9    my ($self, $html) = @_; 
    1010     
    11     unless ($filter->mobile_agent->is_docomo) { 
     11    unless ($self->mobile_agent->is_docomo) { 
    1212        return; 
    1313    } 
    14  
    15     my $guid = HTML::StickyQuery::DoCoMoGUID->new; 
    16     my $html = $filter->html;  
    17     $html = $guid->sticky( scalarref => \$html ); 
    18     $filter->html($html); 
     14     
     15    HTML::StickyQuery::DoCoMoGUID->new->sticky( scalarref => \$html ); 
    1916} 
    2017 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter/EntityReference.pm

    r14597 r14622  
    77 
    88sub filter { 
    9     my ($self, $filter) = @_; 
     9    my ($self, $html) = @_; 
    1010     
    11     my $html = convert_pictogram_entities( 
    12         mobile_agent => $filter->mobile_agent, 
    13         html         => $filter->html, 
     11    convert_pictogram_entities( 
     12        mobile_agent => $self->mobile_agent, 
     13        html         => $html, 
    1414    ); 
    15      
    16     $filter->html($html); 
    1715} 
    1816 
  • lang/perl/HTML-MobileJp-Filter/trunk/lib/HTML/MobileJp/Filter/FallbackImage.pm

    r14597 r14622  
    99 
    1010sub filter { 
    11     my ($self, $filter) = @_; 
     11    my ($self, $html) = @_; 
    1212     
    13     unless ($filter->mobile_agent->is_non_mobile) { 
     13    unless ($self->mobile_agent->is_non_mobile) { 
    1414        return; 
    1515    } 
    1616     
    17     my $html = $filter->{html};  
    18      
    1917    $html =~ s{(\p{InMobileJPPictograms})}{ 
    2018        my $char = Encode::JP::Mobile::Character->from_unicode(ord $1); 
    21         sprintf $self->config->{template}, do { 
    22             $char->$_ for @{ $self->config->{params} || [] }; 
    23         }; 
     19         
     20        sprintf $self->config->{template}, 
     21            map { $char->$_() } @{ $self->config->{params} }; 
     22     
    2423    }ge; 
    25  
    26     $filter->html($html); 
     24     
     25    $html; 
    2726} 
    2827