Text::AutoLink::Plugin - Base Class For Text::AutoLink Plugin


Text-AutoLink documentation Contained in the Text-AutoLink distribution.

Index


Code Index:

NAME

Top

Text::AutoLink::Plugin - Base Class For Text::AutoLink Plugin

SYNOPSIS

Top

  package MyPlugin;
  use strict;
  use base qw(Text::AutoLink::Plugin);
  sub process { ... }

DESCRIPTION

Top

Base class for Text::AutoLink Plugin.

METHODS

Top

new ARGS

Creates a new plugin instance.

target SCALAR

You can specify the "target" attribute of the resulting link here

process SCALARREF

This method must be overridden in the subclass. It receives a scalar ref, which is the text that you should be modifying.

Returns false if not replacement was performed. Returns true otherwise.

linkfy ARGS

href

The link text.

target

The target text. Overrides the value provided to new()

text

The linked text. The value of 'href' is used if not specified.


Text-AutoLink documentation Contained in the Text-AutoLink distribution.

# $Id: /mirror/perl/Text-AutoLink/trunk/lib/Text/AutoLink/Plugin.pm 4207 2007-10-27T13:33:47.814555Z daisuke  $
#
# Copyright (c) 2006 Daisuke Maki <dmaki@cpan.org>
# All rights reserved.

package Text::AutoLink::Plugin;
use strict;
use warnings;

sub new
{
    my $class = shift;
    my %args  = @_;
    my $self = bless {
        target => $args{target} || '',
    }, $class;
    return $self;
}

sub process { die }

sub linkfy
{
    my $self = shift;
    my %args = @_;

    my $target = exists $args{target} ? ($args{target} || '') : $self->{target};
    if ($target) {
        $target = qq| target="$target"|;
    }
    return sprintf('<a href="%s"%s>%s</a>',
        $args{href}, $target, $args{text} || $args{href});
}

1;

__END__