Tuesday, June 17, 2008

3 day 3 release

CPAN generally means responsibility. I released 3 Foorum distribution in the last 3 days.

CPAN means better document. so I tried to use DBICx::AutoDoc to create docs for Foorum::Schema. it's a bit different from the original method in DBICx::AutoDoc. I changed a bit to write pod into Schema files directly.

code are:(briefly)
my $ad = DBICx::AutoDoc->new(
schema => 'Foorum::Schema',
output => File::Spec->catdir($Bin, '..', '..', 'docs'),
);

# rewrite the Schema pm POD
use Template;

my $tt2 = Template->new( { INCLUDE_PATH => $ad->include_path, POST_CHOMP => 0, PRE_CHOMP => 0 } );
my $vars = $ad->get_vars;

# first get the lists of all Foorum::Schema pm files
my @sources = @{ $vars->{sources} };
foreach my $source (@sources) {
my $class = $source->{class}; # Foorum::Schema::User

# make file dir
my @parts_of_modules = split('::', $class);
$parts_of_modules[-1] .= '.pm';
my $file_dir = File::Spec->catfile( $Bin, '..', '..', 'lib', @parts_of_modules );

my $output;
$tt2->process('pod.html', { source => $source }, \$output)
|| die $tt2->error(), "\n";

# replace POD in real module
open(my $fh, '<', $file_dir);
local $/ = undef;
my $in = <$fh>;
close($fh);

my ($code, $pod) = split(/\n1;\n/, $in);
open(my $fh2, '>', $file_dir);
print $fh2 "$code\n1;\n__END__\n\n$output\n";
close($fh2);

print "working on $class\n";
}
Full code can be found in http://foorum.googlecode.com/svn/trunk/bin/misc/dbicx_autodoc.pl

Thanks.

Labels:

0 Comments:

Post a Comment

<< Home