The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

File::Data - access the __DATA__ section in a program module (PM)

SYNOPSIS

  use File::Data

  $fh   = File::FileUtil->pm2datah($pm_file)
  $data = File::FileUtil->pm2data($pm_file)

DESCRIPTION

There are times when the __DATA__ section of a program module (PM) are needed. The "File::Data" methods provides such access.

pm2datah method

 $fh = File::FileUtil->pm2datah($pm_file)

The pm2datah method will open the $pm_file and return a handle positioned at the first /[\012\015]__DATA__/ token occuring in the file. This function is very similar to the DATA file handle that Perl creates when loading a module file with the /[\012\015]__DATA__/ token. The differences is that pm2datah works whether or not the file module is loaded. The method does not close the file handle. Unlike the DATA file handle, which cannot be reused after the module data is read the first time, the pm2datah will always return an opened file handle, the first time, the second time, any time.

CAUTION:

If the /[\012\015]__DATA__/ token appears in the code section, say in a comment, or as a value assigned to a variable, the pm2datah method will misbehave.

pm2data method

 $data = File::FileUtil->pm2data($pm_file)

The pm2data uses the pm2datah to return all the data in a $pm_file form the __DATA__ token to the end of the file.

REQUIREMENTS

Coming soon.

DEMONSTRATION

 ~~~~~~ Demonstration overview ~~~~~

Perl code begins with the prompt

 =>

The selected results from executing the Perl Code follow on the next lines. For example,

 => 2 + 2
 4

 ~~~~~~ The demonstration follows ~~~~~

 =>     use File::Spec;

 =>     use File::Package;
 =>     my $fp = 'File::Package';

 =>     use File::SmartNL;
 =>     my $snl = 'File::SmartNL';

 =>     my $fd = 'File::Data';
 =>     my $loaded = '';
 => my $errors = $fp->load_package($fd)
 => $errors
 ''

 =>  $snl->fin( File::Spec->catfile( '_Drivers_', 'Driver.pm' ) )
 '#!perl
 #
 #
 package  _Drivers_::Driver;

 use strict;
 use warnings;
 use warnings::register;

 use vars qw($VERSION $DATE $FILE );
 $VERSION = '0.02';
 $DATE = '2003/07/04';
 $FILE = __FILE__;

 __DATA__

 =head1 Title Page

  Software Version Description

  for

  ${TITLE}

  Revision: ${REVISION}

  Version: ${VERSION}

  Date: ${DATE}

  Prepared for: ${END_USER} 

  Prepared by:  ${AUTHOR}

  Copyright: ${COPYRIGHT}

  Classification: ${CLASSIFICATION}

 =cut
 '

 =>    my $fh = $fd->pm2datah('_Drivers_::Driver');
 =>    my $actual_datah = $snl->fin($fh);
 =>    $actual_datah =~ s/^\s*(.*)\s*$/$1/gs;
 => $actual_datah
 '=head1 Title Page

  Software Version Description

  for

  ${TITLE}

  Revision: ${REVISION}

  Version: ${VERSION}

  Date: ${DATE}

  Prepared for: ${END_USER} 

  Prepared by:  ${AUTHOR}

  Copyright: ${COPYRIGHT}

  Classification: ${CLASSIFICATION}

 =cut
 '

 =>    $actual_datah = $fd->pm2data('_Drivers_::Driver');
 =>    $actual_datah =~ s/^\s*(.*)\s*$/$1/gs;
 => $actual_datah
 '=head1 Title Page

  Software Version Description

  for

  ${TITLE}

  Revision: ${REVISION}

  Version: ${VERSION}

  Date: ${DATE}

  Prepared for: ${END_USER} 

  Prepared by:  ${AUTHOR}

  Copyright: ${COPYRIGHT}

  Classification: ${CLASSIFICATION}

 =cut
 '

QUALITY ASSURANCE

The module "t::File::Data" is the Software Test Description(STD) module for the "File::Data". module.

To generate all the test output files, run the generated test script, run the demonstration script and include it results in the "File::Data" POD, execute the following in any directory:

 tmake -test_verbose -replace -run  -pm=t::File::Data

Note that tmake.pl must be in the execution path $ENV{PATH} and the "t" directory containing "t::File::Data" on the same level as the "lib" directory that contains the "File::Data" module.

NOTES

AUTHOR

The holder of the copyright and maintainer is

<support@SoftwareDiamonds.com>

Copyrighted (c) 2002 Software Diamonds

All Rights Reserved

BINDING REQUIREMENTS NOTICE

Binding requirements are indexed with the pharse 'shall[dd]' where dd is an unique number for each header section. This conforms to standard federal government practices, 490A ("3.2.3.6" in STD490A). In accordance with the License, Software Diamonds is not liable for any requirement, binding or otherwise.

LICENSE

Software Diamonds permits the redistribution and use in source and binary forms, with or without modification, provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

SOFTWARE DIAMONDS, http::www.softwarediamonds.com, PROVIDES THIS SOFTWARE 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWARE DIAMONDS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING USE OF THIS SOFTWARE, EVEN IF ADVISED OF NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE POSSIBILITY OF SUCH DAMAGE.

SEE_ALSO:

File::PM2File
File::SmartNL