Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supposedly blessed reference is not blessed #35

Closed
kurpitsa opened this issue Dec 8, 2015 · 2 comments
Closed

Supposedly blessed reference is not blessed #35

kurpitsa opened this issue Dec 8, 2015 · 2 comments

Comments

@kurpitsa
Copy link

kurpitsa commented Dec 8, 2015

I have a file A.pm:

package A;

sub test {
bless {};
}

sub somemethod {
print "test";
}

1;

and test.pl:

use A;

works:

A->somemethod();

dies:

A->test()->somemethod();

Now if i run

perl test.pl

Output is:

testtest

But if instead

nodejs ./perlito5.js -I./src5/lib -I./lib -I. ./test.pl

I get:

testCan't locate object method "somemethod" via package "undefined" (perhaps you forgot to load "undefined"?) at ./test.pl line 13
Error
at CORE.die (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:2746:28)
at p5call (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:192:20)
at eval (eval at (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:56), :17:2)
at eval (eval at (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:56), :19:3)
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:11
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42627:7
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42643:6
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42950:5
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42963:4
at Object. (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42964:3)

So the method test does not return a blessed reference as it should. I have compiled perlito5.js using build-5js.

@fglock
Copy link
Owner

fglock commented Dec 9, 2015

I've pushed a fix - "implemented 1-argument bless()":

diff --git a/src5/lib/Perlito5/Javascript2/Emitter.pm
b/src5/lib/Perlito5/Javascript2/Emitter.pm
index 4872748..e509870 100644
--- a/src5/lib/Perlito5/Javascript2/Emitter.pm
+++ b/src5/lib/Perlito5/Javascript2/Emitter.pm
@@ -1607,6 +1607,17 @@ package Perlito5::AST::Apply;
my $self = $_[0];
'p5make_package(' .
Perlito5::Javascript2::escape_string($self->{namespace} ) . ')';
},

  •    'bless' => sub {
    
  •        my ($self, $level, $wantarray) = @_;
    
  •        my $class;
    
  •        if ($self->{arguments}[1]) {
    
  •            $class = Perlito5::Javascript2::to_str(
    
    $self->{arguments}[1] );
  •        }
    
  •        else {
    
  •            $class =
    
    Perlito5::Javascript2::escape_string($Perlito5::PKG_NAME);
  •        }
    
  •        'CORE.bless([' .
    
    $self->{arguments}[0]->emit_javascript2($level, 'scalar') . ', ' . $class .
    '])';
  •    },
     'infix:<~~>' => sub {
         my ($self, $level, $wantarray) = @_;
         my $arg0 = $self->{arguments}->[0];
    

2015-12-08 20:15 GMT+01:00 kurpitsa [email protected]:

I have a file A.pm:

package A;

sub test {
bless {};
}

sub somemethod {
print "test";
}

1;

and test.pl:

use A;

#works:
A->somemethod();

#dies:
A->test()->somemethod();

Now if i run

perl test.pl

Output is:

testtest

But if instead

nodejs ./perlito5.js -I./src5/lib -I./lib -I. ./test.pl

I get:

testCan't locate object method "somemethod" via package "undefined"
(perhaps you forgot to load "undefined"?) at ./test.pl line 13
Error
at CORE.die
(/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:2746:28)
at p5call (/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:192:20)
at eval (eval at
(/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:56), :17:2)
at eval (eval at
(/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:56), :19:3)
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42606:11
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42627:7
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42643:6
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42950:5
at /home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42963:4
at Object.
(/home/ipe/Fortress/game_perl/Perlito-master/perlito5.js:42964:3)

So the method test does not return a blessed reference as it should. I
have compiled perlito5.js using build-5js.


Reply to this email directly or view it on GitHub
#35.

@kurpitsa
Copy link
Author

kurpitsa commented Dec 9, 2015

Ok, seems to work, thanks!

@kurpitsa kurpitsa closed this as completed Dec 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants