Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I tried to track this down for some time (and found the information in require not extremely helpful) - and then tried the approach I recalled from my own past: Just returning a reference to the module's text. This succeeded, for both your sources. Since this is something you mention in your list of attempts as not successful, I'll include the full source of my dbLoader.pm. Could you try this and report what error you get?
package dbLoader; use Carp; use Data::Dumper; use DBI; use Scalar::Util; use strict; use warnings; use feature 'state'; sub import { my $self=shift; return; }; # import: my $KNOWN_PACKAGES_HREF; my ($DBH,$STH); { # INTERNALS: sub _dbLoader { my (undef,$path_S)=@_; s{[/\\]}{::}g, s{\.pm$}{} for (my $package_s=$path_S); return # unless the package is in the this library unless (exists $KNOWN_PACKAGES_HREF->{$package_s}); warn Data::Dumper->Dump([\$path_S,\$package_s],[qw(*path *pack +age)]),' '; my $body_sref; eval { $STH->execute($package_s); if(my $value_aref=$STH->fetchrow_arrayref()) { chomp($value_aref->[0]); $body_sref=\$value_aref->[0]; warn "fetched - ",Data::Dumper->Dump([$body_sref],[qw( +*body)]),''; $INC{$path_S}="DBI:Pg:$path_S"; }; }; if (my $error=$@) { Carp::confess $@; } elsif (!defined $body_sref) { return; } else { open my $fh,'<',$body_sref or Carp::confess "Couldn't open string for reading! $! +"; return ( $body_sref, ); }; }; # _dbLoader: } # INTERNALS: BEGIN { eval { $DBH=DBI->connect('dbi:SQLite:Library.sqlite','','',{ PrintErr +or=>1, RaiseError=>1 }); # Create a (global) hashref of packages/prefixes $STH=$DBH->prepare(<<"__SQL__"); SELECT package FROM packages; __SQL__ $STH->execute(); my $field_aref=$STH->{NAME_lc}; while (my $value_aref=$STH->fetchrow_arrayref()) { my %_h; @_h{@$field_aref}=@$value_aref; $KNOWN_PACKAGES_HREF->{$_h{package}}=undef; }; $STH->finish(); warn Data::Dumper->Dump([\$KNOWN_PACKAGES_HREF],[qw(*KNOWN_PAC +KAGES)]),' '; # Statement handle for fetching source(s) $STH=$DBH->prepare(<<"__SQL__"); SELECT body FROM packages WHERE package = ?; __SQL__ warn "SELECT prepared"; unshift @INC,\&_dbLoader; warn "Prepended \&_dbLoader to \@INC"; }; if (my $error=$@) { Carp::confess $@; }; }; # BEGIN: END { print STDERR sprintf("%40s\t%s\n",$_,$INC{$_}) for (sort grep { $INC{$_} !~ m{^([A-Za-z]:|/)}} keys %INC); }; # END: 1;

In reply to Re: Coderefs and @INC by haj
in thread Coderefs and @INC by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2024-04-23 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found