Pod-Tree

 view release on metacpan or  search on metacpan

lib/Pod/Tree/HTML.pm  view on Meta::CPAN

    my $i = 0;
    for my $child (@$children) {
        $child->is_pod or next;
        $i++ and $node1 = $child;
        $node1 and last;
    }

    $node1 or return undef;    ##no critic (ProhibitExplicitReturnUndef)

    my $text = $node1->get_deep_text;
    ($title) = split m(\s+-), $text;

    $title or return undef;    ##no critic (ProhibitExplicitReturnUndef)
    $title =~ s(\s+$)();

    $title;
}

sub emit_toc {
    my $html = shift;
    $html->{options}{toc} or return;

lib/Pod/Tree/HTML/PerlTop.pm  view on Meta::CPAN

	$html->{links} = $links;
}

sub _emit_verbatim {
	my ( $html, $node ) = @_;
	my $stream = $html->{stream};
	my $links  = $html->{links};
	my $text   = $node->get_text;

	$text =~ s( \n\n$ )()x;
	my @words = split m/(\s+)/, $text;

	$stream->PRE;

	for my $word (@words) {
		if ( $links->{$word} ) {
			my $link = $links->{$word};
			$stream->A( HREF => "$link.html" )->text($word)->_A;
		}
		else {
			$stream->text($word);

lib/Pod/Tree/Node.pm  view on Meta::CPAN

	my ( @text, @link );

	while (@$children) {
		my $child = shift @$children;

		$child->is_text or do {
			push @text, $child;
			next;
		};

		my ( $text, $link ) = split m(\|), $child->{'text'}, 2;
		$link and do {
			push @text, Pod::Tree::Node->text($text) if $text;
			push @link, Pod::Tree::Node->text($link), @$children;
			return ( \@text, \@link );
		};

		push @text, $child;
	}

	( \@text, \@text );

lib/Pod/Tree/PerlDist.pm  view on Meta::CPAN


	my $stop_ext = $perl_dist->{stop_ext};
	my %stop_ext = map { $_ => 1 } @$stop_ext;

	my $stop_base = $perl_dist->{stop_base};
	my %stop_base = map { $_ => 1 } @$stop_base;

	for my $file ( readdir(DIR) ) {
		-f "$perl_dir/$file" and -T "$perl_dir/$file" or next;

		my ( $base, $ext ) = split m(\.), $file;
		$stop_ext{$ext}   and next;
		$stop_base{$base} and next;

		$perl_dist->report2($file);
		$perl_dist->scan_file($file);
	}
}

sub scan_file {
	my ( $perl_dist, $file ) = @_;

lib/Pod/Tree/PerlDist.pm  view on Meta::CPAN


	my $entry = {
		file   => $file,
		source => $source,
		dest   => $dest
	};

	$perl_dist->{index}{$file} = $entry;
	$perl_dist->{options}{link_map}->add_page( $file, $file );

	my ( $base, $ext ) = split m(\.), $file;
	$base eq 'README'
		and $ext
		and $perl_dist->{options}{link_map}->add_page( "perl$ext", $file );
}

sub index {
	my $perl_dist = shift;
	$perl_dist->report1("index");

	my $html_dir = $perl_dist->{html_dir};

lib/Pod/Tree/PerlFunc.pm  view on Meta::CPAN

		my $sibs0   = $item->get_siblings;
		$func0 eq $func1 or @$sibs0 == 0 or last;
	}

	@items;
}

sub Parse_Name {
	my $item  = shift;
	my $text  = $item->get_deep_text;
	my @words = split m([^\w\-]+), $text;

	my $func = $words[0];
	my $file = $func;
	$file =~ tr(A-Za-z0-9_-)()cd;

	( $func, $file );
}

1

lib/Pod/Tree/PerlLib.pm  view on Meta::CPAN

	my $lib_dir  = $perl_lib->{lib_dir};
	$dir =~ s(^$find_dir)($html_dir/$lib_dir);

	$perl_lib->mkdir($dir);
}

sub _scan_file {
	my ( $perl_lib, $source ) = @_;

	$source =~ m(\. (?: pl | pm | pod ) $ )x or return;
	my $file = ( split m(/), $source )[-1];
	$perl_lib->{stop_files}{$file} and return;
	my $module   = $source;
	my $find_dir = $perl_lib->{find_dir};
	$module =~ s(^$find_dir/)();
	$module =~ s( \.\w+$    )()x;    # Foo/Bar

	my $html_dir = $perl_lib->{html_dir};
	my $lib_dir  = $perl_lib->{lib_dir};
	my $dest     = "$html_dir/$lib_dir/$module.html";
	my ( $name, $description ) = $perl_lib->get_name($source);

lib/Pod/Tree/PerlLib.pm  view on Meta::CPAN


sub translate {
	my $perl_lib = shift;
	$perl_lib->report1("translate");

	my $index   = $perl_lib->{index};
	my $options = $perl_lib->{options};

	for my $name ( sort keys %$index ) {
		$perl_lib->report2($name);
		my @path = split m(::), $name;
		my $depth = @path;    # no -1 because they are all under /lib/
		$options->{link_map}->set_depth($depth);

		my $entry  = $index->{$name};
		my $source = $entry->{source};
		my $dest   = $entry->{dest};
		my $html   = Pod::Tree::HTML->new( $source, $dest, %$options );
		$html->translate;
	}
}

lib/Pod/Tree/PerlMap.pm  view on Meta::CPAN

	$perl_map->{force_func} = $force_func;
}

sub map {
	my ( $perl_map, $base, $page, $section ) = @_;

	# print "map $base, $page, $section ->";

	my $prefix     = $perl_map->{prefix};
	my $force_func = $perl_map->{force_func};
	my $func       = ( split m(\s+), $section )[0];    # e.g.  L<"eval BLOCK">
	my $file       = $perl_map->{func}{$func};

	if ( ( $page eq 'perlfunc' or $page eq '' and $force_func ) and $file ) {
		$page    = $prefix . 'pod/func/' . $file;
		$section = '';
	}
	elsif ( $perl_map->{page}{$page} ) {
		$page = $prefix . $perl_map->{page}{$page};
	}

lib/Pod/Tree/PerlPod.pm  view on Meta::CPAN

	my ( $perl_pod, $source, $dest ) = @_;

	$source =~ m( (\w+)\.pod$ )x or return;

	my $link     = $source;
	my $perl_dir = $perl_pod->{perl_dir};
	$link =~ s(^$perl_dir/)();
	$link =~ s( \.pod$ )()x;
	$perl_pod->report2($link);

	my $name = ( split m(/), $link )[-1];
	my $desc = $perl_pod->get_description($source);

	$dest =~ s( \.\w+$ )(.html)x;

	my $pod = {
		name   => $name,      # perldata
		desc   => $desc,      # Perl data types
		link   => $link,      # pod/perldata
		source => $source,    # .../perl5.5.650/pod/perldata.pod
		dest   => $dest

lib/Pod/Tree/PerlPod.pm  view on Meta::CPAN

}

sub _translate {
	my ( $perl_pod, $link ) = @_;

	my $pod     = $perl_pod->{pods}{$link};
	my $source  = $pod->{source};
	my $dest    = $pod->{dest};
	my $options = $perl_pod->{options};

	my @path = split m(\/), $link;
	my $depth = @path - 1;
	$options->{link_map}->set_depth($depth);

	my $html = Pod::Tree::HTML->new( $source, $dest, %$options );
	$html->translate;
}

1

__END__

lib/Pod/Tree/PerlTop.pm  view on Meta::CPAN


	my $dir = $perl_top->{perl_dir};
	opendir( DIR, $dir )
		or die "Pod::Tree::PerlTop::get_dist_links: Can't opendir $dir: $!\n";
	my @files = readdir(DIR);
	closedir(DIR);

	my @README = grep {/^README/} @files;

	for my $file (@README) {
		my ( $base, $ext ) = split m(\.), $file;
		$links->{"perl$ext"} = "../$file";
	}
}

1

__END__

=head1 NAME

lib/Pod/Tree/PerlUtil.pm  view on Meta::CPAN

	my $children = $tree->get_root->get_children;
	my @pod      = grep { $_->is_pod } @$children;
	my $node1    = $pod[1];
	$node1 or return ();

	my $text = $node1->get_deep_text;
	$text =~ s(\s+)( )g;
	$text =~ s(^ )();
	$text =~ s( $)();

	my ( $name, $description ) = split m(\s+-+\s+), $text, 2;
	$name or return ();    # empty!!!

	if ( $name =~ /\s/ and not $description ) {
		$description = $name;
		my @description = split ' ', $description;
		if ( @description > 1 and $description[0] =~ /::/ ) {
			$name = shift @description;              # guess
			$description = join ' ', @description;
		}
		else                                         # desperation
		{
			my @source = split m(/), $source;
			$name = pop @source;
		}
	}

	( $name, $description );
}

sub get_description {
	my ( $node, $source ) = @_;

mod2html  view on Meta::CPAN

sub Hidden {
	my $source = shift;
	$source =~ m(\.pm$) or return 0;
	$source =~ s(\.pm$)(.pod);
	-e $source;
}

sub Depth {
	my $path = shift;
	$path =~ s(^$ModDir/)();
	my @path = split m(/), $path;
	@path - 1;
}

sub Index {
	my $index = "$HTMLDir/index.html";
	my $fh    = IO::File->new(">$index");
	defined $fh or die "Can't open $index: $!\n";

	my $stream = HTML::Stream->new($fh);

pods2html  view on Meta::CPAN

sub Depth {
	my $source = shift;
	my $tree   = Pod::Tree->new;
	$tree->load_file($source);
	my $children = $tree->get_root->get_children;
	my @pod      = grep { $_->is_pod } @$children;
	my $node1    = $pod[1];
	$node1 or return '';

	my $text = $node1->get_deep_text;
	my ($name) = split m(\s+-+\s+), $text;
	$name =~ s(^\s+)();

	my @name = split /::/, $name;
	@name - 1;
}

sub Index {
	my $index = "$HTMLDir/index.html";
	my $fh    = IO::File->new(">$index");
	defined $fh or die "Can't open $index: $!\n";

t/10-cut.t  view on Meta::CPAN

	my $actual   = $tree->dump;
	my $expected = path("$Dir/$dump.exp")->slurp;
	is $actual, $expected;

	path("$Dir/$dump.act")->spew($actual);
}

sub LoadParagraphs {
	my $file       = shift;
	my $string     = path("$file.pod")->slurp;
	my @paragraphs = split m(\n{2,}), $string;
	my $tree       = Pod::Tree->new;

	$tree->load_paragraphs( \@paragraphs );

	my $actual   = $tree->dump;
	my $expected = path("$file.p_exp")->slurp;

	is $actual, $expected;
}



( run in 2.746 seconds using v1.01-cache-2.11-cpan-71847e10f99 )