Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8828547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:37:53+00:00 2026-06-14T07:37:53+00:00

Can you hook the opening of the DATA handle for a module while Perl

  • 0

Can you hook the opening of the DATA handle for a module while Perl is still compiling? And by that I mean is there a way that I can insert code that will run after Perl has opened the DATA glob for reading but before the compilation phase has ceased.

Failing that, can you at least see the raw text after __DATA__ before the compiler opens it up?


In response to Ikegami, on recent scripts that I have been working on, I have been using __DATA__ section + YAML syntax to configure the script. I’ve also been building up a vocabulary of YAML configuration handlers where the behavior is requested by use-ing the modules. And in some scripts that are quick-n-dirty, but not quite enough to forgo strict, I wanted to see if I could expose variables from the YAML specification.

It’s been slightly annoying though just saving data in the import subs and then waiting for an INIT block to process the YAML. But it’s been doable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:37:54+00:00Added an answer on June 14, 2026 at 7:37 am

    I found out that ::STDIN actually gives me access to the stream '-'. And that I can save the current location, through tell( $inh ) and then seek() it when I’m done.

    By using that method, I could read the __DATA__ section in the import sub!

    sub import { 
        my ( $caller, $file ) = ( caller 0 )[0,1];
        my $yaml;
        if ( $file eq '-' ) {
            my $place = tell( ::STDIN );
            local $RS;
            $yaml  = <::STDIN>;
            seek( ::STDIN, $place, 0 );
        }
        else { 
            open( my $inh, '<', $file );
            local $_ = '';
            while ( defined() and !m/^__DATA__$/ ) { $_ = <$inh>; }
            local $RS;
            $yaml = <$inh>;
            close $inh;
        }        
        if ( $yaml ) { 
            my ( $config ) = YAML::XS::Load( $yaml );;
            no strict 'refs';
            while ( my ( $n, $v ) = each %$config ) { 
                *{"$caller\::$n"} = ref $v ? $v : \$v;
            }
        }    
        return;
    }
    

    This worked on Strawberry Perl 5.16.2, so I don’t know how portable this is. But right now, to me, this is working.

    Just a background. I used to do a bit of programming with Windows Script Files. One thing I liked about the wsf format was that you could specify globally useful objects outside of the code. <object id="xl" progid="Application.Excel" />. I have always liked the look of programming by specification and letting some modular handler sort the data out. Now I can get a similar behavior through a YAML handler: excel: !ActiveX: Excel.Application.

    This works for me.

    The test is here, in case you’re interested:

    use strict;
    use warnings;
    use English qw<$RS>;
    use Test::More;
    
    use data_mayhem; # <-- that's my module.
    
    is( $k, 'Excel.Application' );
    is( $l[1], 'two' );
    
    {   local $RS;
        my $data = <DATA>;
        isnt( $data, '' );
        say $data
    }
    
    done_testing;
    
    __DATA__
    ---
    k : !ActiveX Excel.Application
    l : 
      - one
      - two
      - three
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway that I can hook into the tab completion for bash from
Is there such a thing? I know that I can hook my function on
Is there something I can hook into that will fire every time a method
Hope you can help. Is there a way to reliably detect when a stored
Does the iPhone browser have special events that I can hook into with Javascript?
Id there an event I can hook into? I've looked through the docs, and
How we can hook up a code inside a python process so that it
I'm building a generic UI that can hook into a range of underlying object
When using the Aero theme, are there resource names for styles that I can
Is there a way to HOOk browser commands in IE/FF/Chrome Like Office applications? we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.