Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I wrap require and use?

Tags:

require

perl

Let's say I want to wrap require such that,

package MyModule;
use Data::Dumper;

Would output either,

MyModule -> Data::Dumper
MyModule -> Data/Dumper.pm

For all packages and all requires/use statements. How could I do it?

like image 390
NO WAR WITH RUSSIA Avatar asked Nov 30 '20 19:11

NO WAR WITH RUSSIA


People also ask

What material is used to wrap?

At the most basic level, the majority of wraps are made of heavy duty vinyl that has an adhesive backing on one side. With the addition of polyvinyl chloride (PVC), the vinyl material is significantly strengthened.

What is the process of wrapping?

There are six major steps to our in-house wrapping process: Design, Proofing, Printing, Installing, Inspecting, and Educating/Delivery. Design: Designing generally occupies the most time in the vehicle wrap process.

What is the best way to wrap a house?

House wrap is intended to be installed over the sheathing and behind the siding, no matter what siding you are using: wood, fiber cement, vinyl, brick, stucco, and others. Siding manufacturers may recommend specific types of WRB to use with their products.

What is house wrap and how does it work?

House wrap is a fabric, paper, or board material that covers the exterior sheathing of house walls to protect the wall framing. Most siding materials are not totally effective at repelling water, particularly wind-driven rain. When water gets behind the siding, house wrap is there to shed the water and keep it from entering the wall cavity.

How much vinyl wrap do I need to wrap a car?

Gather your tools, supplies, and materials. The average car requires a 25-foot roll of 60-inch wide vinyl wrap. Narrower rolls are available, but this will require making a seam, quite the trick for a first-timer.

Can you use 3-inch tape for house wraps?

You can use the 3-inch tape for any of the house wraps that are wrinkled. Double-check your wrap. After you’re finished securing, you’ll want to check over all the areas. Particularly, you’ll want to look over the top to ensure it’s secured the way it’s supposed to be.


Video Answer


4 Answers

BEGIN {
   unshift @INC, sub {
      printf "%s -> %s\n", ( caller() )[0], $_[1];
      return;
   };
}

See the paragraph starting with "You can also insert hooks into the import facility" in require's documentation.

like image 196
ikegami Avatar answered Oct 19 '22 11:10

ikegami


You cannot reference the require builtin as a subroutine such as for goto, but you can call it from CORE.

use strict;
use warnings;
BEGIN {
  *CORE::GLOBAL::require = sub {
    printf "%s -> %s\n", [caller()]->[0], $_[0];
    CORE::require $_[0];
  }
};
use Data::Dumper;

You may also consider Devel::TraceUse which is similar to the above but more robust and informative, and can easily be invoked from the commandline.

like image 8
Grinnz Avatar answered Oct 19 '22 12:10

Grinnz


You can look inside Devel::TraceUse to see working code for what you are trying to do. But, changing definitions isn't a good plan because you don't know who else also changed definitions and will wonder why their stuff stops working.

You don't need to (or should) override require. Put a code reference in @INC and return false at the end so it looks like that failed and Perl will move on to the next thing in @INC:

#!perl
use v5.10;

# https://stackoverflow.com/a/2541138/2766176
BEGIN {
unshift @INC, sub {
    my( $package, $file ) = caller(0);
    say "$package -> $_[1]";
    return 0;
    };

}

use Data::Dumper;

say "Hello";

This outputs:

main -> Data/Dumper.pm
Data::Dumper -> constant.pm
constant -> strict.pm
constant -> warnings/register.pm
warnings::register -> warnings.pm
Data::Dumper -> Carp.pm
Carp -> overloading.pm
Carp -> Exporter.pm
Data::Dumper -> XSLoader.pm
Data::Dumper -> bytes.pm
Hello
like image 4
brian d foy Avatar answered Oct 19 '22 11:10

brian d foy


Weird requirement needs weird solution: Use a source filter.

#!/usr/bin/perl
{   package Wrap::Use;
    use Filter::Simple sub {
        warn $1 while /use (.*?);/sg;                                  # stupid SO: /
    };
}

BEGIN { Wrap::Use->import }

use strict;
use warnings;
use Time::Piece;
like image 1
choroba Avatar answered Oct 19 '22 13:10

choroba