Data-JavaScript

 view release on metacpan or  search on metacpan

lib/Data/JavaScript.pm  view on Meta::CPAN

package Data::JavaScript;    ## no critic (PodSpelling)

use Modern::Perl;
use Readonly;
use Scalar::Util 'reftype';

our $VERSION = q/1.15/;

# Exporter
Readonly our @EXPORT      => qw(jsdump hjsdump);
Readonly our @EXPORT_OK   => '__quotemeta';
Readonly our %EXPORT_TAGS => (
  all    => [ @EXPORT, @EXPORT_OK ],
  compat => [@EXPORT],
);

# Magic numbers
Readonly my $MIN_ENCODE_REQUIRE_BREAKPOINT => 5.007;
Readonly my $JSCOMPAT_DEFAULT_VERSION      => 1.3;
Readonly my $JSCOMPAT_UNDEFINED_MISSING    => 1.2;

# This is a context variable which holds on to configs.
my %opt = ( JS => $JSCOMPAT_DEFAULT_VERSION );  # TODO: This is super out-dated.

if ( !$] < $MIN_ENCODE_REQUIRE_BREAKPOINT ) { require Encode; }

sub import {
  my ( $package, @args ) = @_;

  # Let's get the stuff we're going to import
  my @explicit_imports = ();
  my @import           = ();
  my %allowable        = map { $_ => 1 } ( @EXPORT, @EXPORT_OK );

  # This is the madness for the JS version
  for my $arg (@args) {
    if ( ref $arg eq 'HASH' ) {
      if ( exists $arg->{JS} )    { $opt{JS}    = $arg->{JS}; }
      if ( exists $arg->{UNDEF} ) { $opt{UNDEF} = $arg->{UNDEF}; }
    }
    elsif ( not ref $arg ) {
      push @explicit_imports, $arg;
    }
  }
  $opt{UNDEF} ||= $opt{JS} > $JSCOMPAT_UNDEFINED_MISSING ? 'undefined' : q('');

  #use (); #imports nothing, as package is not supplied
  if ( defined $package ) {

    if ( scalar @explicit_imports ) {

      # Run through the explicitly exported symbols
      for my $explicit_import (@explicit_imports) {

        # Looks like a tag
        if ( substr( $explicit_import, 0, 1 ) eq q/:/ ) {
          my $tag = substr $explicit_import, 1;

          # Only do things for the actually exported tags.
          if ( not exists $EXPORT_TAGS{$tag} ) { next; }
          push @import, @{ $EXPORT_TAGS{$tag} };
        }

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 5.142 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-48ebf85a1963 )