spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How can I improve the syntax of my AUTOLOADed method names?


It's possible if you can tell that user is a namespace or member rather than a call.

package Class;

sub AUTOLOAD {
    (my $method = our $AUTOLOAD) =~ s/^.*:://s;
    return if $method =~ /DESTROY/;

    my $self = shift;

    return bless([$self, $method],
'Class::Helper');
        if $self->is_namespace($method);

    perform_rpc_call($self, $method, @_);
}


package Class::Helper;

sub AUTOLOAD {
    (my $method = our $AUTOLOAD) =~ s/^.*:://s;
    return if $method =~ /DESTROY/;

    my ($self, $ns) = @{ shift };
    $method = "$ns.$method";

    return bless([$self, $method],
'Class::Helper');
        if $self->is_namespace($method);

    perform_rpc_call($self, $method, @_);
}

That will even work with user.mail.send.


If you can't tell whether user is a namespace or a call, your desired syntax won' twork. You'd have to use

$obj->user->delete->(@args)  #
Error prone. See below

or

$obj->user->delete->call(@args)
 # Same problem, but a little more obvious

or

$obj->api_call('user.delete', @args)

The first option is very error-prone. If you forget that last ->, the RPC method won't get called. I recommend against that one.

This is how the second option would be implemented:

package Class;

sub AUTOLOAD {
    (my $method = our $AUTOLOAD) =~ s/^.*:://s;
    return if $method =~ /DESTROY/;

    my $self = shift;
    return bless([$self, $method],
'Class::Helper');
}


package Class::Helper;

sub AUTOLOAD {
    (my $method = our $AUTOLOAD) =~ s/^.*:://s;
    return if $method =~ /DESTROY/;

    my ($self, $ns) = @{ shift };
    $method = "$ns.$method";
    return bless([$self, $method],
'Class::Helper');
}

sub call {
    my ($self, $method) = @{ shift };
    perform_rpc_call($self, $method, @_);
}

Categories : Perl

Related to : How can I improve the syntax of my AUTOLOADed method names?
git syntax for specifying remote tracking branch versus syntax for git pull, push, checkout etc
First of all, in git pull remote branch, the branch does not correspond to a remote branch but to a local branch. Using that command will pull changes from the remote tracking branch of branch from the remote remote (although that behavior depends a bit on your settings). Nevertheless, using git pull remote/branch would not be a proper alternative there. As for remote tracking branches, remotes/&

Categories : GIT
AngularJS Syntax - John Papa's Bindable up-top Syntax is Ambiguous
Your IDE should be able to handle that, or you could use TypeScript's interfaces to both keep a "up top" and clean implementation in the class itself. I'd recommend Visual Studio (if you do c# / asp.net stuff as well) or Web Storm if not. Web Storm is very cheap and a great editor for web work. Sublime might have some plugins as well.

Categories : Javascript
ACE Editor: disable syntax validation, but keep syntax highlighting
you probably have a typo somewhere else, it works in the attached example <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://ajaxorg.github.io/ace-builds/src/ace.js"></script> <style> #editor1, #editor2 { position: absolute; top: 0; left: 0; right: 0; bottom: 0;} #editor1 {bottom: 50%} #editor2 {top: 50%} </

Categories : Javascript
Improve SQL Server query
I ran your query through a code formatter to help clean it up. I also change the variable declaration since you didn't seem to understand what I was saying. For the record, the way you had it coded you might have missed some rows in the last few milliseconds of the day. I changed the DATEDIFF function to use the datepart name spelled out because it is just too easy use the wrong abbreviation and

Categories : SQL
Possible To Improve On This TSQL Query?
--try this, variant using temp tables --remove calculation from subquery to temp table -------------------------------------------------------------------------------- IF OBJECT_ID('tempdb..#History') IS NOT NULL DROP TABLE #History SELECT History.AlertID , MAX(History.CreatedBy) AS CreatedBy INTO #History FROM [ISG_SOI ].[dbo].[AlertHistory] AS History INNER JOIN [ISG

Categories : Sql Server
Recently Add
unable to connect selenium webDriver through perl bindings
SSL error calling Perl web service via https using LWP
SOAP::Lite always faults in debug mode
perl referencing a hash outside of the scope that populated it (histogram)
Perl script to print out all the lines containing a keyword and the line below it
PERL Unicode Escape string pass from command line argument wrong output
Perl process crashes after handling signal
Marpa: Can I explicitly disallow keywords as identifiers?
Perl: Import text, containing ÅÄÖ, from file
error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
DBIx::Class chaining resultsets with same table in prefetch
Time as input, print timetable in Perl
compare values of different tables perl
Automatically increasing ID generation using PERL
Syntax Error, first line after dostuff
Delete files in a folder using Perl
Perl '-d' operator is not detecting a directory
Perl appending text to new line
write_timeout in IO::Socket::Timeout
Using ForkManager and Perl properly?
Is a cyclic dependency solved with require?
Posting metric to google analytics from perl script
How can I check if a user enters my page the first time?
Sorting arrays of intervals in perl?
Perl: How to get the link target of a soundcloud feed mp3
Uninitialized value in concatenation
Perl code - pipe "|" in `open()` statement
perl command line backticks with matrix
Perl OO - Creating a list of objects
extract gene-id + function annotation from .gff
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.