Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Help Changing use into require/import

by syphilis (Chancellor)
on Mar 07, 2018 at 23:28 UTC ( #1210489=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help Changing use into require/import
in thread Help Changing use into require/import

Can't locate object method "new" via package "Capture::Tiny" at ./foo.pl line 40

Capture::Tiny doesn't have a new() method, and Capture::Tiny->new() will therefore fail irrespective of how you loaded the module.

Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Help Changing use into require/import
by computergeek (Novice) on Mar 08, 2018 at 13:46 UTC

    So is there a way to load it dynamically?

      Just use require Capture::Tiny at runtime, like you already did in your code.

      The thing you are missing is that Perl doesn't know that capture should become a function. You can either try to predeclare capture as subroutine to tell that you expect a capture subroutine:

      sub capture(&@); ... require Capture::Tiny; Capture::Tiny->import('capture'); capture { } ...;

      Or go the more explicit route of calling capture in a way that doesn't need parser gymnastics:

      capture( sub { ... }, ... );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210489]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2018-06-22 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (120 votes). Check out past polls.

    Notices?