Yappo::Hatena::Group::Subtech このページをアンテナに追加 RSSフィード

 | 

2007-10-04

Scalar::Filter 20:11 Scalar::Filter - Yappo::Hatena::Group::Subtech を含むブックマーク はてなブックマーク - Scalar::Filter - Yappo::Hatena::Group::Subtech

Web::Scraper::Filterだけ使うラッパー

package Scalar::Filter;

use strict;
use warnings;

require Carp;
require Web::Scraper;

use overload q{""} => \&as_string;

our $AUTOLOAD;
our $VERSION = '0.01';

sub new {
    my $class  = shift;
    my $scalar = shift;

    bless {
        scalar  => $scalar,
        filters => [],
    }, $class;
}

sub reset {
    my $self = shift;
    my $filters = delete $self->{filters};
    $self->{filters} = [];
    $filters;
}

sub add_filter {
    my($self, $filter, @args) = @_;

    push @{ $self->{filters} }, {
        filter => $filter,
        args   => \@args,
    };
    $self;
}

sub as_string {
    my $self = shift;
    my $filters = $self->reset;
    my $value = $self->{scalar};
    for my $filter (@{ $filters }) {
        $value = eval { Web::Scraper::run_filter($value, $filter->{filter}) };

        if ($@) {
            Carp::croak("Filter $filter->{filter} had an error: $@");
        }
    }
    $value;
}


sub AUTOLOAD {
    my $self = shift;
    my $filter = $AUTOLOAD;
    return if $filter =~ /::DESTROY$/;
    $filter =~ s/.*:://;
    $self->add_filter($filter, @_);
}


1;
package Web::Scraper::Filter::space2lf;
use strict;
use warnings;
use base qw( Web::Scraper::Filter );
sub filter { s/ /\n/g  }
1;
package Web::Scraper::Filter::text2test;
use strict;
use warnings;
use base qw( Web::Scraper::Filter );
sub filter { s/text/test/g  }
1;

test.pl

use strict;
use warnings;

use Scalar::Filter;

my $f = Scalar::Filter->new(' sample text ');

$f->space2lf->text2test;

print $f;

result


sample
test

なんか重いきがす

WidyaWidya 2012/03/24 11:19 Girl you da bomb! I too am such a visual nlraeer. You did a great job as always. I found your blog right after your surgery. I sub to several peoples blogs but when yours pops into my inbox it is the first one I look at. I am just so amazed with your talent. Well I would like to pass along to the other ladies that coffee filters are great to use when embossing or glittering something. They don't have static electricity. Just hold your image over the filter sprinkle your embossing powder on your image. When you are done just fold the filter in half and pour your powder back into the container. No mess and no waste. Thank you for your tutorial. Going to my room to make some flowers.

scclkfqscclkfq 2012/03/24 22:19 56O1MI <a href="http://jdffmnxhlhvr.com/">jdffmnxhlhvr</a>

wbqnkmduwmwbqnkmduwm 2012/03/25 23:44 9bqMC1 , [url=http://vaibkseopwee.com/]vaibkseopwee[/url], [link=http://gbmetyygcrhs.com/]gbmetyygcrhs[/link], http://onrcbjxotkgl.com/

stfrswiiustfrswiiu 2012/03/26 04:45 7ZTcRK <a href="http://vyswpbulmdqq.com/">vyswpbulmdqq</a>

ゲスト



トラックバック - http://subtech.g.hatena.ne.jp/yappo/20071004
 |