1package RPC::ExtDirect::Demo::TestAction;
2
3use strict;
4use warnings;
5no  warnings 'uninitialized';
6
7use Carp;
8
9use RPC::ExtDirect Action => 'TestAction';
10
11sub doEcho : ExtDirect(1) {
12    my ($class, $data) = @_;
13
14    return $data;
15}
16
17sub multiply : ExtDirect(1) {
18    my ($class, $num) = @_;
19
20    croak "Call to multiply with a value that is not a number"
21        unless $num =~ / \A \d+ \z /xms;
22
23    return $num * 8;
24}
25
26sub getTree : ExtDirect(1) {
27    my ($class, $id) = @_;
28
29    return if length $id == 3;
30
31    return [ map { { id => "n$_", text => "Node $_", leaf => \0 } } 1..5 ]
32        if $id eq 'root';
33
34    my ($parent) = $id =~ /n(\d)/;
35
36    return [
37        map { { id => "$id$_", text => "Node $parent.$_", leaf => \1 } } 1..5
38    ];
39}
40
41sub getGrid : ExtDirect( params => [ 'sort' ] ) {
42    my ($class, %params) = @_;
43
44    my $field     = $params{sort}->[0]->{property};
45    my $direction = $params{sort}->[0]->{direction};
46
47    my $sort_sub = sub {
48        my ($foo, $bar)         = $direction eq 'ASC' ? ($a, $b)
49                                :                       ($b, $a)
50                                ;
51        return $field eq 'name' ? $foo->{name}     cmp $bar->{name}
52                                : $foo->{turnover} <=> $bar->{turnover}
53                                ;
54    };
55
56    my @data = sort $sort_sub (
57        { name => 'ABC Accounting',         turnover => 50000   },
58        { name => 'Ezy Video Rental',       turnover => 106300  },
59        { name => 'Greens Fruit Grocery',   turnover => 120000  },
60        { name => 'Icecream Express',       turnover => 73000   },
61        { name => 'Ripped Gym',             turnover => 88400   },
62        { name => 'Smith Auto Mechanic',    turnover => 222980  },
63    );
64
65    return [ @data ];
66}
67
68sub showDetails : ExtDirect(params => [qw(firstName lastName age)]) {
69    my ($class, %params) = @_;
70
71    my $first = $params{firstName};
72    my $last  = $params{lastName};
73    my $age   = $params{age};
74
75    return "Hi $first $last, you are $age years old.";
76}
77
781;
79