All pastes #779141 Raw Edit

Untitled

public c v1 · immutable
·published 2007-11-18 06:35 UTC
rendered paste body
    char perl_definitions[] =    {        /* We use to function one to load a file the other to execute         * the string obtained from the first and holding the file         * contents. This allows to have a really local $/ without         * introducing temp variables to hold the old value. Just a         * question of style:) */        "package Purple::PerlLoader;"        "use Symbol;"        "{"        "    no strict 'refs';"        ""        "    my $func = 'Glib::bootstrap';"        "    my $old  = \\&{ $func };"        ""        "    *{ $func } = sub {"        "        $old->(@_) if $old;"        ""        "        for my $domain (undef, qw/Glib Glib-Object/) {"        "            Glib::Log->set_handler("        "                    $domain,"        "                    [qw/recursion fatal error critical warning message info debug/],"        "                    sub {"        "                    },"        "            );"        "    };"        "}"        "sub load_file {"          "my $f_name=shift;"          "local $/=undef;"          "open FH,$f_name or return \"__FAILED__\";"          "$_=<FH>;"          "close FH;"          "return $_;"        "}"        "sub destroy_package {"          "eval { $_[0]->UNLOAD() if $_[0]->can('UNLOAD'); };"          "Symbol::delete_package($_[0]);"        "}"        "sub load_n_eval {"          "my ($f_name, $package) = @_;"          "destroy_package($package);"          "my $strin=load_file($f_name);"          "return 2 if($strin eq \"__FAILED__\");"          "my $eval = qq{package $package; $strin;};"          "{"          "  eval $eval;"          "}"          "if($@) {"            /*"  #something went wrong\n"*/            "die(\"Errors loading file $f_name: $@\");"          "}"          "return 0;"        "}"    };