What could be the reason that `require` doesn't work in some places? - require

Loading a module (ABC) with require works in one module of a distribution while it fails in another module of the distribution.
What could be the reason that loading ABC with require fails in one place?
require Name::ABC;
my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC)
perl6 -v
This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.
The the required module: App::DBBrowser::Subqueries
App::DBBrowser::Union, line 80: OK *
App::DBBrowser::Join, lines 66 and 191: OK *
App::DBBrowser::Table::Extensions, line 49: OK *
App::DBBrowser, line 690: You cannot create an instance of this type (Subqueries) *
App::DBBrowser::CreateTable, line 112: You cannot create an instance of this type (Subqueries) *
* version 0.0.1

$ cat XXX.pm6
unit class XXX;
$ cat ZZZ.pm6
module ZZZ {
require XXX;
XXX.new;
say "OK";
}
$ perl6 -I. -e 'use ZZZ;'
===SORRY!===
You cannot create an instance of this type (XXX)
From the documentation:
require loads a compunit and imports definite symbols at runtime.
You are doing a runtime load of a module while also expecting the symbols for that module to exist at compile time. Instead you should use indirect name lookup (as shown at the bottom of the documentation page linked earlier):
$ cat XXX.pm6
unit class XXX;
$ cat ZZZ.pm6
module ZZZ {
require XXX;
::("XXX").new;
say "OK";
}
$ perl6 -I. -e 'use ZZZ;'
OK

I think it's because require is a runtime load whereas use is compile time.
Generally I'd use use unless I have a need for dynamic module loading at runtime.

use loads and imports a module at compile-time while require only loads a module at runtime.
Since the namespace is checked at compile-time, you can't just access it as you would a module that is loaded and imported with use.
You can get around that by symbolic references, but you can also capture the namespace into a variable.
(Assuming there is only a single namespace in the module, and it is the same as the name used to load it)
Foo.pm6:
unit module Foo;
sub fubar () { say 'fubar' }
my \Foo = do require Foo;
Foo::fubar(); # fubar␤
(Note that the name of the variable doesn't have to be the same.)

Related

Prevent exec command running on module unload ibm load sharing facilty

I have a tcl script which is a modulefile within the IBM Load Sharing Facitily (lsf) used to configure some environment variables and launch a python script by using the exec command.
When the module is unloaded normally the opposite of all the commands are run, but also the exec command is run as normal. I would like it so that the exec part is only run on module load and not on module unload.
Here is what I tried so far
if { !(is-loaded mymodule)} {
exec .venv/bin/python mypython.py
}
I also tried this
if { module-info command load } {
exec .venv/bin/python mypython.py
}
For each one I get a similar error
Module ERROR: invalid bareword "module"
in expression " module-info command [load] ";
should be "$module" or "{module}" or "module(...)" or ...
both exceptions complain either about an invalid bareword (either "is" or "module") depending on which snippet I try. Is my snytax invalid?
My syntax was incorrect, in the end I was able to solve the problem with the following:
set is_load_command [module-info command load]
if { $is_load_command == 1 } {
exec .venv/bin/python mypython.py
}
I had two problems, correctly understanding comparisons in tcl and using return values from a called function. Neither really behaved how I am used to.

puppet 4 Duplicate declaration

I am getting a duplicate declaration error when I don't think I should.
I am using the following puppet version
puppet --version
4.3.2
This is the directory structure
./manifests
./manifests/site.pp
./modules
./modules/main
./modules/main/manifests
./modules/main/manifests/init.pp
./modules/main/manifests/sub.pp
site.pp
node default {
include main
include main::sub
}
init.pp
class main {
notice("main")
}
sub.pp
class main::sub {
notice("sub")
}
I run this command
puppet apply --modulepath ./modules manifests/site.pp
It yields this output:
Notice: Scope(Class[Main]): main
Notice: Scope(Class[Main::Sub]): sub
Notice: Compiled catalog for black-pearl.hsd1.il.comcast.net in environment production in 0.82 seconds
Error: Duplicate declaration: Class[Main] is already declared; cannot redeclare
I'm not sure why this happens, perhaps puppet has a main already. When I substituted ryan in for main all was well.
$ find .
.
./manifests
./manifests/site.pp
./modules
./modules/ryan
./modules/ryan/manifests
./modules/ryan/manifests/init.pp
./modules/ryan/manifests/sub.pp
site.pp
node default {
include ryan
include ryan::sub
}
Puppet 4 is a lot stricter about names, and there are a number of reserved names, including main:
Reserved Class Names
The following are built-in namespaces used by Puppet and so must not be used as class names:
main — Puppet automatically creates a main class, which contains any resources not contained by any other class.
See https://docs.puppetlabs.com/puppet/latest/reference/lang_reserved.html
for more

Puppet Could not find dependency Class

I am trying to pull things out into roles and profiles and am having an issue. I am using puppet apply for all of this as I am using it to finish setting up my Puppet Master. If I define my node in site.pp as shown here:
[root#puppet puppetdbsetup]# cat manifests/site.pp
node 'puppet' {
include ::roles::puppetmaster
}
I get this error:
[root#puppet puppetdbsetup]# puppet apply manifests/site.pp --environmentpath /etc/puppet/environments --environment puppetdbsetup --noop
Notice: Compiled catalog for puppet.belkin in environment puppetdbsetup in 1.29 seconds
Error: Could not find dependency Class[Puppet::Install] for File[/etc/puppet/hiera.yaml] at /etc/puppet/environments/puppetdbsetup/modules/p
uppet/manifests/master.pp:31
If I run puppetmaster.pp (shown below) with puppet apply directly it doesn't throw the same error.
[root#puppet puppetdbsetup]# cat modules/roles/manifests/puppetmaster.pp
class roles::puppetmaster {
#include profiles::base
include profiles::puppet::master
}
Can anyone tell me why this is and how to fix it? As a side note, all three modules referenced here are hand written... none are Forge modules.
Update 1
Here is my puppet::install class:
[root#puppet puppetdbsetup]# cat modules/puppet/manifests/install.pp
class puppet::install {
package { 'puppet':
ensure => present,
}
}
Somewhere in your manifest, you are declaring a File[/etc/puppet/hiera.yaml] that depends on Class[Puppet::Install], like
file { '/etc/puppet/hiera.yaml': require => Class['puppet::install'] }
or so
Class['puppet::install'] -> file { '/etc/puppet/hiera.yaml': ... }
or something in that vein.
What you are lacking is the actual declaration of the class either via
include puppet::install # nice!
or
class { 'puppet::install': } # please don't
If in doubt, add the include line near the file declaration. It is usually safe to include a class multiple times.
If you apply puppetmaster.pp directly, you're just defining the class not applying it.
You need to do puppet apply -e 'include ::roles::puppetmaster' to be comparible.
The other error is probably caused by modules/puppet/manifests/install.pp not existing, or the class definition in the file not starting with
class puppet::install (
....
....
) {

What directory should I use for "error: 'extra_PROGRAMS' is used but 'extradir' is undefined"?

I have a autoconf/automake system that has a stand-alone target called stand. I don't want stand to be normally built, so I have this in my Makefile.am:
bin_PROGRAMS = grace
extra_PROGRAMS = stand
...
stand_SOURCES = stand.cpp barry.cpp ...
This has worked for a while, but automake just got updated on my system and I'm now getting this error:
src/Makefile.am:4: error: 'extra_PROGRAMS' is used but 'extradir' is undefined
src/Makefile.am:66: warning: variable 'stand_SOURCES' is defined but no program or
src/Makefile.am:66: library has 'stand' as canonical name (possible typo)
So I added this:
extradir = .
But that has caused problems.
I don't want the stand program installed. It's just a test program for me. But it's not part of a formal test suite, it's just for my own purposes. What should I do?
We found the bug! It turns out that extra needs to be capitalized, like this:
bin_PROGRAMS = grace
EXTRA_PROGRAMS = stand
...
stand_SOURCES = stand.cpp barry.cpp ...
You could try conditionally building it:
noinst_PROGRAMS=
if BUILD_STAND
noinst_PROGRAMS += stand
endif
stand_SOURCES = stand.cpp barry.cpp ...
This will not install it since it's in noinst_PROGRAMS and others will normally not build it since BUILD_STAND will normally not be defined for them.

Haddock: Failed to create dependency graph (when adding sections with * or a module heading)

I compiled and installed haddock-2.4.2 from the tarball source.
Adding a few simple comments to the code here:
https://dl.getdropbox.com/u/143480/doc/DualMap.hs
and running haddock
$ haddock -h -o doc Data/DualMap.hs
Warning: Data.DualMap: could not find link destinations for:
Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show GHC.Base.Ord GHC.Base.Bool Data.Set.Set
yields:
https://dl.getdropbox.com/u/143480/doc/Data-DualMap.html
Things look good. (Note that this module only depends on libs that ship with GHC and no other source modules.)
However, when I try to add sections (a la http://www.haskell.org/haddock/doc/html/ch03s04.html#id289234 ) in the comments with "-- * test" I get:
$ haddock -h -o doc Data/DualMap.hs
Data/DualMap.hs:20:0: parse error on input `-- * test'
haddock: Failed to create dependency graph
I have no idea where to begin getting this to work since this error message only tells me that Haddock.Interface.depanal returned Nothing (according to a grep of the haddock sources) but not how to stop the dependency analysis from failing. Perhaps I need some more command line arguments or references to missing link destinations in GHC/base/containers documentation or some haddock config file?
Searching Google yielded plenty of cabal build errors of the same ilk for packages on hackage but nothing about how to fix them.
How do I add sections (with asterisks) and get Haddock to generate my docs? What (probably simple thing) am I missing?
Simple fix (terrible error message):
Move the ( up to the line with the module name. Previous bad code:
module Data.DualMap
-- * The #DualMap# abstract type
( DualMap ()
-- * (?) internal? -- exposed for testing purposes, for now...
, dmFlip
-- * converting to and from DualMap
, toList, fromList, map
-- * constructing a DualMap
, empty, null, insert, union
Happy code looks like this:
module Data.DualMap (
-- * The #DualMap# abstract type
DualMap ()
-- * (?) internal? -- exposed for testing purposes, for now...
, dmFlip
-- * converting to and from DualMap
, toList, fromList, map
-- * constructing a DualMap
, empty, null, insert, union
Simple enough. I found this out by downloading DList from hacakge and gutting it and replacing the code with my own code. When DList worked with 'cabal haddock' and mine didn't (when I tried to add some asterisks), I looked at the difference between the files and sure enough my parenthesis was on the wrong line.
BTW I highly recommend DList as a starting place for a new Haskell project instead of hnop.

Resources