Changeset 8672

Show
Ignore:
Timestamp:
04/02/08 20:34:30 (5 years ago)
Author:
yappo
Message:

lang/perl/HTTP-MobileAttribute?: accessor っぽいの実装したよ

Location:
lang/perl/HTTP-MobileAttribute/trunk/lib/HTTP/MobileAttribute
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-MobileAttribute/trunk/lib/HTTP/MobileAttribute/Plugin.pm

    r8668 r8672  
    33use warnings; 
    44use base qw/Class::Component::Plugin/; 
     5 
     6sub mk_register_accessors { 
     7    my $self = shift; 
     8    my $c     = shift; 
     9    my $class = ref $self; 
     10 
     11    for my $method (@_) { 
     12        no strict 'refs'; 
     13        *{"$class\::$method"} = sub { shift->{$method} } unless *{"$class\::$method"}{CODE}; 
     14        $c->register_method( $method => $self ); 
     15    } 
     16} 
    5171; 
  • lang/perl/HTTP-MobileAttribute/trunk/lib/HTTP/MobileAttribute/Plugin/Default/DoCoMo.pm

    r8668 r8672  
    99    my ( $self, $c ) = @_; 
    1010    return unless $c->carrier_longname eq 'DoCoMo'; 
     11    $self->mk_register_accessors( $c => qw/version model status bandwidth serial_number is_foma card_id xhtml_compliant comment/); 
    1112 
    1213    $self->parse( $c ); 
    1314} 
    1415 
    15 # FIXME: ここなんとかして。どうにかして。なんか anonymous function だと Attribute がうまくあたらないからとりあえずこれで。 
    16 for my $method (qw/version model status bandwidth serial_number is_foma card_id xhtml_compliant comment/) { 
    17     eval qq! sub $method :MobileMethod('DoCoMo') { shift->{$method} }; !; ## no critic. 
    18     die $@ if $@; 
    19 } 
    2016 
    2117sub name : MobileMethod('DoCoMo') { shift->{name} }