ZMQ-Declare

 view release on metacpan or  search on metacpan

lib/ZMQ/Declare/DSL.pm  view on Meta::CPAN

  (undef, undef, undef, my $function) = caller(1);
  $function =~ s/^.*:://;

  Carp::croak("'$function' outside ZDCF found: Did you fail to call 'declare_zdcf'?")
    if not defined $CurScope;
  Carp::croak("Wrongly nested or out-of-place '$function' detected: You cannot nest ZDCF '${function}'s")
    if ($global_state_var_ref && $$global_state_var_ref)
    or $CurScope ne $expected_scope;
}

sub declare_zdcf(&) {
  local $ZDCF = {version => "1.0"};
  local $CurScope = 'zdcf';
  # Clear the various components in this dynamic scope
  local $App;
  local $Context;
  local $Device;
  local $Socket;
  $_[0]->();
  return ZMQ::Declare::ZDCF->new(tree => $ZDCF);
}

sub app(&) {
  _check_scope('zdcf', \$App);

  local $CurScope = 'app';
  local $App = {};
  $_[0]->();

  my $name = delete $App->{name};
  Carp::croak("Missing app name!") if not defined $name;
  $ZDCF->{apps}{$name} = $App;
}

sub context(&) {
  _check_scope('app' => \$Context);

  local $Context = {};
  local $CurScope = 'context';
  $_[0]->();
  $App->{context} = $Context;
}

sub iothreads($) {
  _check_scope('context');
  $Context->{iothreads} = $_[0];
}

sub device(&) {
  _check_scope('app' => \$Device);

  local $Device = {};
  local $CurScope = 'device';
  $_[0]->();

  my $name = delete $Device->{name};
  if (not defined $name) {
    $name = $App->{name};
  }

lib/ZMQ/Declare/DSL.pm  view on Meta::CPAN


sub type($) {
  if (not defined $CurScope) {
    Carp::croak("Error 'type()' outside device, and socket. Did you fail to call 'declare_zdcf'?");
  }
  elsif ($CurScope eq 'device') { $Device->{type} = shift }
  elsif ($CurScope eq 'socket') { $Socket->{type} = shift }
  else { Carp::croak("Error 'type()' outside device, and socket") }
}

sub sock(&) {
  _check_scope('device' => \$Socket);

  local $Socket = {};
  local $CurScope = 'socket';
  $_[0]->();

  my $name = delete $Socket->{name};
  Carp::croak("Missing socket name!") if not defined $name;
  $Device->{sockets}{$name} = $Socket;
}



( run in 0.525 second using v1.01-cache-2.11-cpan-49f99fa48dc )