From: Chris W. <la...@us...> - 2004-12-05 08:51:35
|
Update of /cvsroot/openinteract/OpenInteract2/pkg/system_doc/OpenInteract2/Action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16278/pkg/system_doc/OpenInteract2/Action Modified Files: SystemDoc.pm Log Message: update packages to move as many messages as possible out of code and into message files; use new add_status/add_error shortcuts Index: SystemDoc.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/pkg/system_doc/OpenInteract2/Action/SystemDoc.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SystemDoc.pm 9 Jun 2004 01:09:59 -0000 1.12 --- SystemDoc.pm 5 Dec 2004 08:51:24 -0000 1.13 *************** *** 131,135 **** my $request = CTX->request; ! my ( $pod_file, $html_file, $text_file, $title, $error ); # If this is a package, display the doc --- 131,136 ---- my $request = CTX->request; ! my %params = map { $_ => '' } ! qw( pod_file html_file text_file title error ); # If this is a package, display the doc *************** *** 137,242 **** my $package_spec = $request->param( 'package' ); if ( $package_spec ) { ! my ( $package_name, $ver ) = ! OpenInteract2::Package->parse_full_name( $package_spec ); ! my $doc = $request->param( 'doc' ); ! my $repos = CTX->repository; ! if ( $doc =~ /\.(html|txt|pod)$/ ) { ! my $full_filename = $repos->find_file( $package_name, $doc ); ! $log->is_debug && ! $log->debug( "Found [$full_filename] in [$package_name]" ); ! $pod_file = $full_filename if ( $doc =~ /\.pod$/ ); ! $html_file = $full_filename if ( $doc =~ /\.html$/ ); ! $text_file = $full_filename if ( $doc =~ /\.txt$/ ); ! $title = "Display Document from Package: $package_name"; ! $error = "Cannot find package documentation: $doc"; ! } } else { my $module = $self->param( 'module' ) || $request->param( 'module' ); ! ! # ewww! ick! ! # TODO: Can we programmatically use Pod::Perldoc to do this? ! $pod_file = $POD_CACHE{ $module } || `perldoc -l $module`; ! ! chomp $pod_file; ! if ( $pod_file ) { ! $log->is_info && ! $log->info( "Found [$pod_file] from [$module]" ); ! } ! else { ! $pod_file = $INC{ _uncolonify( $module ) }; ! $log->is_info && ! $log->info( "Found [$pod_file] from %INC" ); ! } ! if ( -f $pod_file ) { ! $POD_CACHE{ $module } = $pod_file; ! } ! $title = "Display Module: $module"; ! $error = "Cannot find module: $module"; } my ( $content ); ! if ( -f $pod_file ) { ! $log->is_debug && ! $log->debug( "Trying to view pod in [$pod_file]" ); ! my $parser = Pod::POM->new(); ! my $pom = $parser->parse( $pod_file ); ! unless ( $pom ) { ! $log->error( "Pod::POM did not return an object: ", ! $parser->error() ); ! return '<p>Error parsing POD: ' . $parser->error() . '</p>'; ! } ! ! eval { require OpenInteract2::PodView }; ! if ( $@ ) { ! my $msg = "Failed to load POD viewer: $@"; ! $log->error( $msg ); ! $self->param_add( error_msg => $msg ); ! $content = 'No content'; ! } ! else { ! $content = eval { OpenInteract2::PodView->print( $pom ) }; ! if ( $@ ) { ! $log->error( "Failed to output html from pod: $@" ); ! $content = "Failed to display module: $@"; ! } ! else { ! $content =~ s/^.*<BODY>//sm; ! $content =~ s|</BODY>.*$||sm; ! } ! } } ! elsif ( -f $html_file ) { ! eval { open( HTML, $html_file ) || die $! }; ! if ( $@ ) { ! my $msg = "Error opening HTML file '$html_file': $@"; ! $log->error( $msg ); ! return "<p>$msg</p>"; ! } ! local $/ = undef; ! $content = <HTML>; ! close( HTML ); ! $content =~ s/^.*<BODY>//sm; ! $content =~ s|</BODY>.*$||sm; } ! elsif ( -f $text_file ) { ! eval { open( TEXT, $text_file ) || die $! }; ! if ( $@ ) { ! my $msg = "Error opening TEXT file '$text_file': $@"; ! $log->error( $msg ); ! return "<p>$msg</p>"; ! } ! local $/ = undef; ! $content = <TEXT>; ! close( TEXT ); ! $content = qq(<pre class="systemDocText">$content</pre>); } else { ! return "<p>Error $error.</p>"; } --- 138,165 ---- my $package_spec = $request->param( 'package' ); if ( $package_spec ) { ! $self->_display_package_params( $package_spec, \%params ); } else { my $module = $self->param( 'module' ) || $request->param( 'module' ); ! $self->_display_module_params( $module, \%params ); } my ( $content ); ! if ( -f $params{pod_file} ) { ! $content = $self->_show_pod( \%params ); } ! elsif ( -f $params{html_file} ) { ! $content = $self->_show_html( \%params ); } ! elsif ( -f $params{text_file} ) { ! $content = $self->_show_text( \%params ); } else { ! return "<p>$params{error}.</p>"; } *************** *** 249,252 **** --- 172,277 ---- } + sub _display_package_params { + my ( $self, $package_spec, $params ) = @_; + my ( $package_name, $ver ) = + OpenInteract2::Package->parse_full_name( $package_spec ); + my $request = CTX->request; + my $doc = $request->param( 'doc' ); + my $repos = CTX->repository; + if ( $doc =~ /\.(html|txt|pod)$/ ) { + my $full_filename = $repos->find_file( $package_name, $doc ); + $log->is_debug && + $log->debug( "Found [$full_filename] in [$package_name]" ); + $params->{pod_file} = $full_filename if ( $doc =~ /\.pod$/ ); + $params->{html_file} = $full_filename if ( $doc =~ /\.html$/ ); + $params->{text_file} = $full_filename if ( $doc =~ /\.txt$/ ); + $params->{title} = $self->_msg( 'sys_doc.package.doc_title', $package_name ); + $params->{error} = $self->_msg( 'sys_doc.error.cannot_find_package_doc', $doc ); + } + } + + sub _display_module_params { + my ( $self, $module, $params ) = @_; + + # ewww! ick! + # TODO: Can we programmatically use Pod::Perldoc to do this? + $params->{pod_file} = $POD_CACHE{ $module } || `perldoc -l $module`; + + chomp $params->{pod_file}; + if ( $params->{pod_file} ) { + $log->is_info && + $log->info( "Found [$params->{pod_file}] from [$module]" ); + } + else { + $params->{pod_file} = $INC{ _uncolonify( $module ) }; + $log->is_info && + $log->info( "Found [$params->{pod_file}] from %INC" ); + } + if ( -f $params->{pod_file} ) { + $POD_CACHE{ $module } = $params->{pod_file}; + } + $params->{title} = $self->_msg( 'sys_doc.module.doc_title', $module ); + $params->{error} = $self->_msg( 'sys_doc.error.cannot_find_module_doc', $module ); + } + + sub _show_pod { + my ( $self, $params ) = @_; + $log->is_debug && + $log->debug( "Trying to view pod in [$params->{pod_file}]" ); + my $parser = Pod::POM->new(); + my $pom = $parser->parse( $params->{pod_file} ); + unless ( $pom ) { + $log->error( "Pod::POM did not return an object: ", + $parser->error() ); + my $msg = $self->_msg( 'sys_doc.error.pod_parse', $parser->error() ); + return qq(<p>$msg</p>); + } + + eval { require OpenInteract2::PodView }; + if ( $@ ) { + $log->error( "No POD viewer: $@" ); + $self->add_error_key( 'sys_doc.error.pod_viewer', $@ ); + return $self->_msg( 'sys_doc.pod.no_content' ); + } + my $content = eval { OpenInteract2::PodView->print( $pom ) }; + if ( $@ ) { + $log->error( "Failed to output html from pod: $@" ); + return $self->_msg( 'sys_doc.pod.cannot_display_module', $@ ); + } + $content =~ s/^.*<BODY>//sm; + $content =~ s|</BODY>.*$||sm; + return $content; + } + + sub _show_html { + my ( $self, $params ) = @_; + eval { open( HTML, $params->{html_file} ) || die $! }; + if ( $@ ) { + my $msg = $self->_msg( 'sys_doc.error.cannot_open_file', + $params->{html_file}, $@ ); + $log->error( $msg ); + return "<p>$msg</p>"; + } + my $content = join( '', <HTML> ); + close( HTML ); + $content =~ s/^.*<BODY>//sm; + $content =~ s|</BODY>.*$||sm; + return $content; + } + + sub _show_text { + my ( $self, $params ) = @_; + eval { open( TEXT, $params->{text_file} ) || die $! }; + if ( $@ ) { + my $msg = $self->_msg( 'sys_doc.error.cannot_open_file', + $params->{text_file}, $@ ); + $log->error( $msg ); + return "<p>$msg</p>"; + } + my $content = join( '', <TEXT> ); + close( TEXT ); + return qq(<pre class="systemDocText">$content</pre>); + } + 1; *************** *** 304,311 **** display title and other information on the listing page. - =head1 BUGS - - None known. - =head1 COPYRIGHT --- 329,332 ---- |