summaryrefslogtreecommitdiffstats
path: root/static/talks/ox_yapc_na_2011/012.pl.html
blob: 96cd998b3ed32b9d0c0c86c51424ccd4f40cfe46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<html>
<head>
<title>012.pl</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function navigate(e) {
    var keynum = (window.event) // IE
        ? e.keyCode
        : e.which;
    if (keynum == 8) {
        window.location = "011.pl" + ".html";
        return false;
    }
    if (keynum == 13 || keynum == 32) {
        window.location = "013" + ".html";
        return false;
    }
    if (keynum == 73 || keynum == 105) {
        window.location = "index.html";
        return false;
    }
    return true;
}
</script>
</head>
<body onkeypress="return navigate(event)">
<pre>

    package Controller;
    use Moose;
    
    has view  =&gt; (is =&gt; 'ro', isa =&gt; 'View',  required =&gt; 1);
    has model =&gt; (is =&gt; 'ro', isa =&gt; 'Model', required =&gt; 1);
    
    sub index { }
    sub inc   { my $self = shift; $self-&gt;model-&gt;inc }
    sub dec   { my $self = shift; $self-&gt;model-&gt;dec }
    sub reset { my $self = shift; $self-&gt;model-&gt;reset }
    sub set   { my $self = shift; $self-&gt;model-&gt;set($_[1]) }
    
    around [qw(index inc dec set reset)] =&gt; sub {
        my $orig = shift;
        my $self = shift;
        $self-&gt;$orig(@_);
        return $self-&gt;view-&gt;render($self-&gt;model-&gt;count);
    };
    
    __PACKAGE__-&gt;meta-&gt;make_immutable;
    1;





</pre>
</body>