TUI-Vision

 view release on metacpan or  search on metacpan

lib/TUI/toolkit.pm  view on Meta::CPAN

        require Moose;
        Moose->import::into( $caller, @syms );
        last;
      };
      is_Moo and do {
        require Moo;
        Moo->import::into( $caller, @syms );
        last;
      };
      is_Moos and do {
        require Moos;
        _my_moos_export( $caller, @syms );
        _around_hook( $caller, has => \&_my_moos_has ) if $want{has};
        _add_demolish( 'Moos::Object' ) unless $ADDED{DEMOLISH}++;
        last;
      };
      is_UNIVERSAL and do {
        require TUI::toolkit::UO::Antlers;
        TUI::toolkit::UO::Antlers->import::into( $caller, @syms );
        last;
      };
      DEFAULT: {
        warn "No backend for TUI::toolkit\n";
        last;
      }
    } #/ SWITCH:

  } #/ if ( my @syms = grep {...})
  
  # boolean backend routing
  if ( $want{true} || $want{false} ) {
    require TUI::toolkit::boolean;
    TUI::toolkit::boolean->import::into( $caller, 
      grep { $want{$_} } qw( true false )
    );
  }

  # assert routed to backend
  if ( $want{assert} ) {
    if ( XS_ASSERT and not PERL_ONLY ) {
      # suppress void warnings for XS backend
      warnings->unimport( 'void' );
      PerlX::Assert->import::into( $caller, 'assert' );
    }
    else {
      PerlX::Assert::PP->import::into( $caller );
    }
  }

  # signature routed to backend
  if ( $want{signature} ) {
    if ( XS_PARAMS and not PERL_ONLY ) {
      Type::Params->import::into( $caller, 'signature' );
    }
    else {
      TUI::toolkit::Params->import::into( $caller, 'signature' );
    }
  }

  # Add a dump method to the class if it doesn't already have one
  $^H{ __PACKAGE__ . "/$caller" } = autodie::Scope::Guard->new(sub {
    _add_dump( $caller ) unless $caller->can( 'dump' );
  });

  # exports living in this module
  Importer->import_into( $class, $caller, @{ $EXPORT_TAGS{backend} } );
} #/ sub import

sub unimport {
  my $caller = caller();
  return unless $^H{ __PACKAGE__ . "/$caller" };

  if ( XS_PARAMS and not PERL_ONLY ) {
    Type::Params->unimport::out_of( $caller );
  }
  else {
    TUI::toolkit::Params->unimport::out_of( $caller );
  }
  if ( XS_ASSERT and not PERL_ONLY ) {
    PerlX::Assert->unimport::out_of( $caller );
  }
  else {
    PerlX::Assert::PP->unimport::out_of( $caller );
  }
  TUI::toolkit::boolean->unimport::out_of( $caller );
  if ( is_Moose ) {
    Moose->unimport::out_of( $caller );
  }
  elsif ( is_Moo ) {
    Moo->unimport::out_of( $caller );
  }
  elsif ( is_Moos ) {
    Moos->unimport::out_of( $caller );
  } 

  $^H{ __PACKAGE__ . "/$caller" } = 0;
}

# Split fully qualified name into package and symbol
sub _split_fqn {    # ($pkg, $sym) = _split_fqn($fqn)
  my ( $fqn ) = @_;
  assert ( defined $fqn && !ref $fqn );
  my ( $pkg, $sym ) = $fqn =~ m/^(.*)::([^:]+)\z/ 
                    ? ( $1, $2 ) 
                    : ( 'main', $fqn );
  $pkg = 'main' if !defined( $pkg ) || $pkg eq '';
  return ( $pkg, $sym );
}

# Get the symbol table hash for a package, or undef if it does not exist
sub _get_package_stash {    # \%stash|undef ($pkg)
  my ( $pkg ) = @_;
  assert ( defined $pkg && !ref $pkg );

  return \%:: if $pkg eq '' || $pkg eq 'main';

  $pkg =~ s/::\z//;
  my @parts = split /::/, $pkg;
  my $stash = \%::;    # main::

  no strict 'refs';



( run in 0.544 second using v1.01-cache-2.11-cpan-5b529ec07f3 )