Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
*very* hacky first take on $/ and $¢
They're only available inside regex embedded blocks.
  • Loading branch information
sorear committed Aug 23, 2010
1 parent 16c4aaa commit 36e966d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Body.pm
@@ -1,6 +1,7 @@
use strict;
use warnings;
use 5.010;
use utf8;
use CodeGen ();
use CgOp ();

Expand Down Expand Up @@ -29,6 +30,9 @@ use CgOp ();
has file => (isa => 'Str', is => 'ro');
has text => (isa => 'Str', is => 'ro');

# wtf is this doing here
has cname => (isa => 'Str', is => 'rw');

# metadata for runtime inspection
has class => (isa => 'Str', is => 'rw', default => 'Sub');
has ltm => (is => 'rw');
Expand Down Expand Up @@ -112,6 +116,12 @@ use CgOp ();
value => CgOp::letvar('pkg'))) if $self->type =~ /mainline|class|
package|grammar|module|role|slang|knowhow/x;

if ($self->cname) {
$::process->(
Decl::VarAlias->new(oname => $self->cname, nname => '$/'),
Decl::VarAlias->new(oname => $self->cname, nname => ''));
}

if ($self->type eq 'mainline') {
$::process->(
Decl::Hint->new(name => '$?GLOBAL',
Expand Down
26 changes: 26 additions & 0 deletions src/Decl.pm
Expand Up @@ -447,6 +447,32 @@ use CgOp;
no Moose;
}

# XXX CHEAP HACK ALERT
{
package Decl::VarAlias;
use Moose;
extends 'Decl';

has oname => (is => 'ro', isa => 'Str', required => 1);
has nname => (is => 'ro', isa => 'Str', required => 1);

sub used_slots { [ $_[0]->nname, 'Variable', 0 ] }

sub preinit_code {
my ($self, $body) = @_;
return CgOp::noop unless $body->needs_protovars;
CgOp::proto_var($self->nname, CgOp::scopedlex($self->oname));
}

sub enter_code {
my ($self, $body) = @_;
CgOp::scopedlex($self->nname, CgOp::scopedlex($self->oname));
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Decl::Hint;
use Moose;
Expand Down
1 change: 1 addition & 0 deletions src/RxOp.pm
Expand Up @@ -385,6 +385,7 @@ use CgOp;

sub op {
my ($self, $cn, $cont) = @_;
$self->block->invocant->body->cname($cn); #XXX
$cn, Op::StatementList->new(children => [$self->block, $cont]);
}

Expand Down

0 comments on commit 36e966d

Please sign in to comment.