# Copyright (C) 2007, The Perl Foundation. # $Id: Utils.pm 23327 2007-12-02 02:41:57Z petdance $ package Parrot::Ops2pm::Utils; use strict; use warnings; use Cwd; use Data::Dumper (); use File::Path (); use File::Spec; use lib ("lib/"); use Parrot::OpsFile; =head1 NAME Parrot::Ops2pm::Utils - Methods holding functionality for F. =head1 SYNOPSIS use Parrot::Ops2pm::Utils; $self = Parrot::Ops2pm::Utils->new( { argv => [ @ARGV ], nolines => $nolines_flag, renum => $renum_flag, moddir => "lib/Parrot/OpLib", module => "core.pm", inc_dir => "include/parrot/oplib", inc_f => "ops.h", script => "tools/build/ops2pm.pl", } ); $self->prepare_ops(); if ($renum_flag) { $self->renum_op_map_file(); exit 0; } $self->load_op_map_files(); $self->sort_ops(); $self->prepare_real_ops(); $self->print_module(); $self->print_h(); exit 0; =cut =head1 DESCRIPTION Parrot::Ops2pm::Utils provides methods called by F, a program which is called at the very beginning of the Parrot F process. The program's function is to build two files: =over 4 =item * F =item * F =back The functionality originally found in F has been extracted into this package's methods in order to support component-focused testing and future refactoring. =cut ############### Package-scoped Lexical Variables ############### my $NUM_FILE = "src/ops/ops.num"; my $SKIP_FILE = "src/ops/ops.skip"; ############### Subroutines ############### =head1 METHODS =head2 C =over 4 =item * Purpose Process files provided as command-line arguments to F and construct a Parrot::Ops2pm::Utils object. =item * Arguments Hash reference with the following elements: argv : reference to @ARGV nolines : set to true value to eliminate #line directives in output renum : set to true value if moddir : directory where output module is created (generally, lib/Parrot/OpLib) module : name of output module (generally, core.pm) inc_dir : directory where C-header file is created (generally, include/parrot/oplib) inc_f : name of output C-header file (generally, ops.h) script : name of the script to be executed by 'make' (generally, tools/build/ops2pm.pl) =item * Return Value Parrot::Ops2pm::Utils object. =item * Comment Arguments for the constructor have been selected so as to provide subsequent methods with all information needed to execute properly and to be testable. A Parrot::Ops2pm::Utils object I be constructed lacking some of these arguments and still suffice for the execution of particular methods -- this is done during the test suite -- but such an object would not suffice for F's call to F. =back =cut sub new { my ( $class, $argsref ) = @_; my @argv = @{ $argsref->{argv} }; my $file = shift @argv; die "$argsref->{script}: Could not find ops file '$file'!\n" unless -e $file; $argsref->{file} = $file; $argsref->{argv} = \@argv; return bless $argsref, $class; } =head2 C =over 4 =item * Purpose Call C, then populate the resulting C<$opts> hash reference with information from each of the F<.ops> files provided as command-line arguments to F. =item * Arguments None. (Implicitly requires that at least the C and C