package Text::Trac;

use strict;
use warnings;

use 5.006;
use Text::Trac::Context;
use Text::Trac::BlockNode;

our $VERSION = '0.24';

my %Defaults = (
	html              => '',
	permalink         => '',
	min_heading_level => 1,
	class             => 1,
	id                => 1,
	span              => 1,

sub new {
	my ( $class, %args ) = @_;

	my $self = { %Defaults, %args, };

	bless $self, $class;

sub parse {
	my $self = shift;
	my $text = shift or return;

	$self->{trac_url} = '/' unless defined $self->{trac_url};
	for ( keys %$self ) {
		if ( $_ =~ /^trac.+url$/ ) {
			$self->{$_} .= '/' if $self->{$_} !~ m!/$!;

	my $c = Text::Trac::Context->new(
			%$self, text => $text,

	my $node = Text::Trac::BlockNode->new(
			context => $c,

	$self->{html} = $c->html;

sub html { $_[0]->{html}; }

*process = \&parse;


=head1 NAME

Text::Trac - Perl extension for formatting text with Trac Wiki Style.


    use Text::Trac;

    my $parser = Text::Trac->new(
        trac_url      => '',
        disable_links => [ qw( changeset ticket ) ],


    print $parser->html;


Text::Trac parses text with Trac WikiFormatting and convert it to html format.

=head1 METHODS

=head2 new

Constructs Text::Trac object.

Available arguments are:

=head3 trac_url

Base URL for TracLinks.Default is /. You can specify each type of URL individually.
Available URLs are:


=item trac_attachment_url

=item trac_changeset_url

=item trac_log_url

=item trac_milestone_url

=item trac_report_url

=item trac_source_url

=item trac_ticket_url

=item trac_wiki_url


=head3 disable_links

Specify TracLink types you want to disable.
All types are enabled if you don't specify this option.

    my $parser = Text::Trac->new(
        disable_links => [ qw( changeset ticket ) ],

=head3 enable_links

Specify TracLink types you want to enable.Other types are disabled.
You cannot use both disable_links and enable_links at once.

    my $parser = Text::Trac->new(
        enable_links => [ qw( changeset ticket ) ],

=head2 parse

Parses text and converts it to html format.

=head2 process

An alias of parse method.

=head2 html

Return converted html string.

=head1 SEE ALSO

=over 3

=item  L<Text::Hatena>

=item  L<Trac Guide|>

=item  L<Trac WikiFormatting|>


=head1 AUTHORS

Gosuke Miyashita, C<< <gosukenator at> >>

Hideaki Tanaka, C<< <drawn.boy at> >>

=head1 BUGS

Please report any bugs or feature requests to
C<bug-text-trac at>, or through the web interface at
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Text::Trac

You can also look for information at:

=over 4

=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * RT: CPAN's request tracker


=item * Search CPAN




Copyright 2006 Gosuke Miyashita, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.