Re: Version of a Module

2017-07-04 Thread Lloyd Fournier
It is a bug. It's because of the way require is implemented at the moment
is a little rough. The first one is asking for the .^ver of a stub package
require has inserted. ::("Bailador").ver should work.

LL

On Wed, Jul 5, 2017 at 4:46 AM Martin Barth  wrote:

> Hi there,
>
> is this a bug?
>
> > perl6 -Ilib -e 'require Bailador; say Bailador.^ver'
> No such method 'ver' for invocant of type 'Perl6::Metamodel::PackageHOW'
>   in block  at -e line 1
>
> vs
>
> > perl6 -Ilib -e 'use Bailador; say Bailador.^ver'
> v0.0.7
>
> it seems that there a 2 different metaclasses being used:
>
> > perl6 -Ilib -e 'use Bailador; say Bailador.HOW'
> Perl6::Metamodel::ModuleHOW.new
>
> > perl6 -Ilib -e 'require Bailador; say Bailador.HOW'
> Perl6::Metamodel::PackageHOW.new
>
> Am 28.06.2017 um 14:16 schrieb Simon Proctor:
>
> See I'm using mi6 to generate my META6.json file from the report and it
> picks the version up from the module file. Other options like that seem
> sensible to me.
>
> Simon
>
> On Wed, 28 Jun 2017, 13:01 Martin Barth,  wrote:
>
>> Hello,
>>
>> but your approach means you have to state the version in the META6.json
>> AND in the Module.pm6 file again. This would be the similar to having
>> $VERSION in perl5. Shouldnt there be a simpler way?
>>
>>
>> Am 28.06.2017 um 08:45 schrieb Fernando Santagata:
>>
>> Hi Martin,
>>
>> This works for me:
>>
>> File mytest.pm6
>>
>> use v6;
>> unit module mytest:ver<0.0.1>;
>>
>> sub myver is export
>> {
>>   mytest.^ver;
>> }
>>
>> File mytest.p6
>>
>> #!/usr/bin/env perl6
>> use lib '.';
>> use mytest;
>>
>> say myver;
>>
>> Console output:
>>
>> $./mytest.p6
>> v0.0.1
>>
>> I this what you meant?
>>
>> On Tue, Jun 27, 2017 at 10:37 PM, Martin Barth  wrote:
>>
>>> Hello everyone,
>>>
>>> I wanted to repeat the question that I asked today on #perl6.
>>> I am looking for a way to retrieve the version of a Perl6-Module from
>>> within the module itself.
>>>
>>>  there is often a our $VERSION in perl5 modules. is this still
>>> idiomatic/a good way to go in perl6
>>>  i think the version is meant to be part of the meta info and
>>> such?
>>>  but that means the module itself does not know about its
>>> version, just e.g. zef does?
>>>  i'm convinced there ought to be a way to get the full meta
>>> info from whatever installation your script was grabbed from
>>>  but i don't know what or how
>>>
>>
>>
>>
>> --
>> Fernando Santagata
>>
>>
>>
>


Re: not enough memory

2017-06-29 Thread Lloyd Fournier
I'm not sure if it's related but I've been getting a few weird memory
related issues with HEAD and zef. e.g my travis build just segfaulted:

https://travis-ci.org/spitsh/spitsh/builds/248242106#L1355

And a day or so ago I got:

"MoarVM panic: Heap corruption detected: pointer 0x7f0fe9a16410 to past
fromspace"
https://travis-ci.org/spitsh/spitsh/builds/247357557#L1355

Are you also using a recent rakudo?

LL


On Thu, Jun 29, 2017 at 4:37 PM Gabor Szabo  wrote:

> hi,
>
> I've got this "not enough memory" twice today while trying to upgrade
> some packages using zef.
> Once when I ran 'zef upgrade zef' and then again when I ran
> 'zef --debug upgrade Bailador'.
>
> In both cases the error was shown during the running of the tests.
>
> After running the first command again it worked.
>
> The second command kept the same error message.
>
> This machine had 1 Gb memory.
>
> After adding another Gb the second command worked as well.
>
> Gabor
>


Re: Version of a Module

2017-06-27 Thread Lloyd Fournier
Hi Martin,

AFAIK you can only do this with hacks atm. It's different if the module is
installed or if you are in the source directory doing pelr6 -Ilib.

I do this in my own module here:
https://github.com/spitsh/spitsh/blob/master/lib/Spit/Util.pm6#L61

LL


On Wed, Jun 28, 2017 at 7:14 AM Martin Barth  wrote:

> Hello everyone,
>
> I wanted to repeat the question that I asked today on #perl6.
> I am looking for a way to retrieve the version of a Perl6-Module from
> within the module itself.
>
>  there is often a our $VERSION in perl5 modules. is this still
> idiomatic/a good way to go in perl6
>  i think the version is meant to be part of the meta info and
> such?
>  but that means the module itself does not know about its
> version, just e.g. zef does?
>  i'm convinced there ought to be a way to get the full meta
> info from whatever installation your script was grabbed from
>  but i don't know what or how
>


Re: ding!

2017-05-31 Thread Lloyd Fournier
perl6 -e 'say "\a"'

Will print the alarm character which causes an annoying  sound on my mac.
Other than that, you'll have to investigate the module ecosystem or shell
out to something.

LL

On Thu, Jun 1, 2017 at 1:24 PM ToddAndMargo  wrote:

> Hi All,
>
> Does Perl 6 have a build in "ding" sound, or do I
> need to make a system call (which I do all
> the time in bash script)?
>
> Many thanks,
> -T
>
> --
> ~
> When we ask for advice, we are usually looking for an accomplice.
> --  Charles Varlet de La Grange
> ~
>


Re: Absolute path to directory of the current perl program

2017-05-28 Thread Lloyd Fournier
After thinking about what Zoffix said, probably what you're meant to do is:

$*PROGRAM.parent.absolute

Which leaves the stringification (.absolute) until last.

On Sun, May 28, 2017 at 4:04 PM Lloyd Fournier <lloyd.fo...@gmail.com>
wrote:

> FYI:
>
> 15:57 < llfourn> Zoffix: is there any plan to make .dirname and .absolute
> on IO::Path return an IO::Path?
> 15:58 < llfourn> (rather than a Str)
> 15:58 < Zoffix> llfourn: no
> 15:58 < Zoffix> .absolute is one of the two ways to stringify an IO::Path
> (the second being .relative)
> 15:58 < Zoffix> And .dirname is part of .parts; all Str objects as well
>
> On Sun, May 28, 2017 at 3:54 PM Gabor Szabo <szab...@gmail.com> wrote:
>
>> thanks.
>>
>> $*PROGRAM.dirname.IO.absolute;
>>
>> also works, but yours seem better.
>>
>> As a side note, dirname does not return and IO::Path object either.
>>
>> Gabor
>>
>>
>> On Sat, May 27, 2017 at 6:48 PM, Lloyd Fournier <lloyd.fo...@gmail.com>
>> wrote:
>> > I'd use
>> >
>> > $*PROGRAM.absolute.IO.dirname
>> >
>> > I'm not sure why .absolute doesn't return an IO::Path object. Maybe
>> that's
>> > being addressed as part of Zoffix++'s IO work.
>> >
>> >
>> > On Sat, May 27, 2017 at 10:07 PM Gabor Szabo <szab...@gmail.com> wrote:
>> >>
>> >> I came up with this:
>> >>
>> >> say $*PROGRAM-NAME.IO.absolute.IO.dirname;
>> >>
>> >> but I wonder if there is a simpler way to do it?
>> >>
>> >> regards
>> >> Gabor
>>
>


Re: Absolute path to directory of the current perl program

2017-05-28 Thread Lloyd Fournier
FYI:

15:57 < llfourn> Zoffix: is there any plan to make .dirname and .absolute
on IO::Path return an IO::Path?
15:58 < llfourn> (rather than a Str)
15:58 < Zoffix> llfourn: no
15:58 < Zoffix> .absolute is one of the two ways to stringify an IO::Path
(the second being .relative)
15:58 < Zoffix> And .dirname is part of .parts; all Str objects as well

On Sun, May 28, 2017 at 3:54 PM Gabor Szabo <szab...@gmail.com> wrote:

> thanks.
>
> $*PROGRAM.dirname.IO.absolute;
>
> also works, but yours seem better.
>
> As a side note, dirname does not return and IO::Path object either.
>
> Gabor
>
>
> On Sat, May 27, 2017 at 6:48 PM, Lloyd Fournier <lloyd.fo...@gmail.com>
> wrote:
> > I'd use
> >
> > $*PROGRAM.absolute.IO.dirname
> >
> > I'm not sure why .absolute doesn't return an IO::Path object. Maybe
> that's
> > being addressed as part of Zoffix++'s IO work.
> >
> >
> > On Sat, May 27, 2017 at 10:07 PM Gabor Szabo <szab...@gmail.com> wrote:
> >>
> >> I came up with this:
> >>
> >> say $*PROGRAM-NAME.IO.absolute.IO.dirname;
> >>
> >> but I wonder if there is a simpler way to do it?
> >>
> >> regards
> >> Gabor
>


Re: Absolute path to directory of the current perl program

2017-05-27 Thread Lloyd Fournier
I'd use

$*PROGRAM.absolute.IO.dirname

I'm not sure why .absolute doesn't return an IO::Path object. Maybe that's
being addressed as part of Zoffix++'s IO work.

On Sat, May 27, 2017 at 10:07 PM Gabor Szabo  wrote:

> I came up with this:
>
> say $*PROGRAM-NAME.IO.absolute.IO.dirname;
>
> but I wonder if there is a simpler way to do it?
>
> regards
> Gabor
>


Re: Parse a string into a regex?

2017-05-12 Thread Lloyd Fournier
Patrick's answer of <$regex-interpolation> is the one I'd use.

Although it checks a few possibly malicious things it doesn't catch
everything:
https://rt.perl.org/Public/Bug/Display.html?id=131079

On Fri, May 12, 2017 at 5:11 PM Andreas Mueller <
andreas.muel...@biologie.uni-osnabrueck.de> wrote:

>   IMHO  it is a security and speed issu
>
>   I switched it of with a pragma like this:
>
> use MONKEY-SEE-NO-EVAL;
> my $match = EVAL "/$m/";
>
> if $test_string ~~ $match { say 'yea' }
>
>
>   Andreas
>
> On 11.05.17 10:32, Sean McAfee wrote:
> > I've been searching for how to parse a string into a regex, like qr/$str/
> > does in Perl 5, but so far without success.
> >
> > At first I assumed, by analogy with .Str, .List, etc, that I could call
> > .Regex on a string, but this is not the case.
> >
> > On IRC's #perl6 I learned about the <$str> construct, which doesn't
> really
> > create a new regex, but keeps a reference to the string around, with some
> > (to me) surprising semantics:
> >
> > my $str = 'foo';
> > my $re = rx/<$str>/;
> > $str = 'bar';
> > 'foo' ~~ $re;  # no match
> >
> > Still, it's *almost* sufficient for my needs, except that for the
> purposes
> > of a golfing challenge I'm working on, I want to parse the argument to a
> > WhateverCode object into a regex, but this:
> >
> > map rx/<*>/, ;
> >
> > ...rather predictably doesn't work.
> >
> > So, is there in fact any way to simply parse a string into a brand-new
> > Regex object?
>
> --
> Andreas Müller - Raum: 35/114b - Tel: 2875
>


Re: Fwd: Re: Variables in modules

2017-03-15 Thread Lloyd Fournier
Since $?FILE in modules is being discussed I'll just leave this RT here:

https://rt.perl.org/Public/Bug/Display.html?id=128442

On Thu, Mar 16, 2017 at 4:50 AM JuhiMarcel LangbroekTimmerman <
mt195...@gmail.com> wrote:

> In the perl doc of IO, IO::Path etc. The type is $?File.IO.WHAT to search
> for.
>
> Or $?File.IO.^methods but that is only a list of methods.
>
>
> Marcel
>
>
> On March 13, 2017 23:29:15 ToddAndMargo  wrote:
>
> >>
> >>
> >> On March 10, 2017 10:32:43 PM Theo van den Heuvel
> >>  wrote:
> >>
> >>> Not with me it doesn't.
> >>>
> >>> my $TheValue = $?FILE.subst(/.* "/"/, "", :g);
> >>> sub sayfn is export { $TheValue.say }
> >>>
> >>> Could something else be wrong here?
> >>>
> >>> cheers,
> >>> Theo
> >>>
> >>> ToddAndMargo schreef op 2017-03-10 22:10:
>  On 03/10/2017 09:53 AM, Timo Paulssen wrote:
> > I don't quite understand what's wrong with just
> >
> > my $TheValue = $?FILE.subst(/.* "/"/, "" :g);
> >
> > near the top of your module?
> >
> 
>  Hi Timo,
> 
>  Because it gives you "Use of uninitialized value $TheValue"
>  when you go to use it inside one of the "is export" subs
> 
>  :'(
> 
>  Many thanks,
>  -T
> >
> > On 03/13/2017 02:01 AM, JuhiMarcel LangbroekTimmerman wrote:
> >  > now we are at it, for readability perhaps instead of substitutes do,
> >  >
> >  > my $thevalue = $?FILE.IO.basename;
> >  >
> >  > Marcel
> >
> >
> > Hi Marcel,
> >
> > Sweet.  Thank you!
> >
> > Is there a list somewhere of all the tings I can tack onto the
> > $?FILE variable?
> >
> > perl6 -e 'say $?FILE.perl;'
> >
> > Didn't work
> >
> > -T
> >
> > --
> > ~~
> > Computers are like air conditioners.
> > They malfunction when you open windows
> > ~~
>


Re: mocking Proc

2017-02-27 Thread Lloyd Fournier
Ah nice. Wrapping  makes more sense than augmenting Proc anyway.

LL



On Tue, Feb 28, 2017 at 4:22 AM Brian Duggan  wrote:

> On Monday, February 27, Brian Duggan wrote:
> > I tried numerous variants with multis and signatures that match the
> > existing signatures, but didn't have any success.
>
> Okay, looks like wrap does what I want:
>
> use module;
>
> ( sub (|args) { say 'bye' } );
> hello;
>
> Brian
>


Re: mocking Proc

2017-02-27 Thread Lloyd Fournier
I was thinking just do: 'sub shell(...) is export { }'. And then 'use
MyCrazyShell;'  in module.pm.

Do you mean without modifying module.pm?

LL

On Tue, Feb 28, 2017 at 1:46 AM Brian Duggan <bdugg...@gmail.com> wrote:

> On Monday, February 27, Lloyd Fournier wrote:
> > I'd do the follwiing:
> >
> > 1. make a sub named shell to overwrite the existing one that calls .shell
> > on Proc.
>
> Once I make a 'shell', is it possible for the test file
> to inject my 'shell' into module.pm's namespace?
>
> e.g. I was hoping for something like
>
> $::(CLIENT::<>) = sub (...) { ... }
>
> ?
>
> Brian
>


Re: mocking Proc

2017-02-27 Thread Lloyd Fournier
I'd do the follwiing:

1. make a sub named shell to overwrite the existing one that calls .shell
on Proc.
2. make a class that inherits from Proc: class MyProc is Proc { }
3. Look at https://github.com/rakudo/rakudo/blob/nom/src/core/Proc.pm and
decide what methods you need to override to get the behaviour you want.
4. return a MyProc from your custom shell()

LL

On Tue, Feb 28, 2017 at 12:45 AM Brian Duggan  wrote:

> Hi perl6-users,
>
> Suppose I have a file like this:
>
> # module.pm
> sub hello is export {
> shell "echo hello world"
> }
>
> and another like this:
>
> # test.t
> use module;
> hello;
>
> I want to have 'hello' invoke a 'shell' that I write,
> rather than the real one, so that I can mock the
> behavior of a command.  What would be the best way
> to do this?
>
> thanks
> Brian
>


Re: Simple windows code example needed

2017-01-11 Thread Lloyd Fournier
say "hello world";
or on the command line:
perl6 -e 'say "hello world"'

There are no headers :)

LL


On Thu, Jan 12, 2017 at 2:28 PM ToddAndMargo  wrote:

Hi All,

Please forgive me being a mooch here.  Would some kind person please
write me a simple Windows perl 6 script so that I can see the headers?
A simple write "hello" to the screen will suffice.

Many thanks,
-T



--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Need help with Nil values

2016-02-23 Thread Lloyd Fournier
You could just do:

method new (Str $value?) { ... } # makes value optional

and then not pass anything to .new.

On Tue, Feb 23, 2016 at 1:27 PM TS xx  wrote:

> Thanks Brandon,
>
>
> That was what I was looking for.
>
> I'm trying it already.
>
>
> Regards,
>
> Emiliano
>
>
> --
> *From:* Brandon Allbery 
> *Sent:* Tuesday, February 23, 2016 2:21 AM
> *To:* TS xx
> *Cc:* perl6-users@perl.org
>
> *Subject:* Re: Need help with Nil values
> On Mon, Feb 22, 2016 at 9:15 PM, TS xx  wrote:
>
>> I expect $.value to hold Strings, but I want to be able to instantiate
>> MyClass whether I have a value already or not, and I also want to be able
>> to tell if $.value has a real String or not. Is this possible?
>
>
> You don't want Nil there; it's not the undefined value, it's a value of a
> special type. You want Str, the type object for Strings, which also serves
> as the undefined value (also true for other types). You can test it with
> `defined`.
>
> $myObject = MyClass.new(Str);
>
> then you can test $!value.defined or whatever.
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: How to call a super class method?

2015-10-28 Thread Lloyd Fournier
I just re-read your question and saw your emphasis on "non-static" context.
I'm not 100% sure what you are looking for, but take a look at *BUILD:*

http://docs.perl6.org/language/objects#Submethods

LL

On Wed, Oct 28, 2015 at 2:31 PM, TS xx  wrote:

> Hello fellow perl users,
>
> I have been trying to understand perl 6 oop implementation, and one thing
> I still can't figure out is how to call super class methods from lower
> classes.
> Let's say we have two classes, Person and Employee, and the method I am
> trying to access is the object constructor:
>
> class Person {
> method new ($argument) {
> #do some things
> }
> }
>
> class Employee is Person {
> method new () {
> #call here Person's method new
> #do more things
> }
> }
>
> Can I call the Person's constructor (in non static context), pass the
> required parameter and do more things before returning?
>
>
> Regards,
> Emiliano
>


Re: How to call a super class method?

2015-10-28 Thread Lloyd Fournier
Hi Emiliano,

You could do this:

class Person {
has $.name;
method new($name) {
   # do some things
   self.bless(:$name);
}
}

class Employee is Person {

my $counter = 1;
method new () {
# Employees don't have individual identities so we give them a name
:(
my $new-employee = callwith("employee#{$counter++}");
# ... do whatever you want to $new-employee here
return $new-employee;
}
}

my $e1 = Employee.new();

say $e1.WHAT#-> (Employee)

=

This works because even in *Person.new()* the *self* is still an
*Employee *type so
when it calls *bless* you still get a *Employee* object instance back. The
*callwith* (which I just noticed is not searchable in docs.per6.org nor is
it mentioned in the context of constructors in the tutorial) is not too
magical, and in this case can be replaced with
self.new(employee#{$counter++}"). It's just there to prevent an infinite
loop if you decide to add an argument to *Employee.new*.

Cheers

LL


On Wed, Oct 28, 2015 at 2:31 PM, TS xx  wrote:

> Hello fellow perl users,
>
> I have been trying to understand perl 6 oop implementation, and one thing
> I still can't figure out is how to call super class methods from lower
> classes.
> Let's say we have two classes, Person and Employee, and the method I am
> trying to access is the object constructor:
>
> class Person {
> method new ($argument) {
> #do some things
> }
> }
>
> class Employee is Person {
> method new () {
> #call here Person's method new
> #do more things
> }
> }
>
> Can I call the Person's constructor (in non static context), pass the
> required parameter and do more things before returning?
>
>
> Regards,
> Emiliano
>