File: FakeCatalystObject.pm

package info (click to toggle)
libmojomojo-perl 1.01%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,272 kB
  • ctags: 879
  • sloc: perl: 14,055; sh: 145; xml: 120; ruby: 6; makefile: 2
file content (129 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (5)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# See the difference among Dummy, Stub, Fake and Mock objects at
# http://xunitpatterns.com/Mocks,%20Fakes,%20Stubs%20and%20Dummies.html
package FakeCatalystObject;
use URI;
my $reverse;
my %prefs = (
    main_formatter => 'MojoMojo::Formatter::Markdown',
);

sub new {
    my $class = shift;
    bless {}, $class;
}

sub req {
    return $_[0];
}

sub res {
    return $_[0];
}

sub base {
    $_[0]->{path} ||= '/';
    return URI->new("http://example.com/");
}

sub reverse {
    return $reverse;
}

sub set_reverse {
    $reverse=$_[1];
}

sub stash {
    my $self = shift;
    return {
        page => $self,
        page_path => 'http://example.com/',
    };
}

sub flash {
    my $self = shift;
    return {
        page => $self,
        page_path => 'http://example.com/',
    };
}

sub path {
    my $self = shift;
    $path = $self->{path};
    return $path;
}

sub model {
    return $_[0];
}

sub result_source {
    return $_[0];
}

sub resultset {
    return $_[0];
}

sub ajax {}

sub action {
    return $_[0];
}

sub name { 'view' }


sub path_pages {
    my ($self, $path) = @_;
    $path =~ s|^/||;
    if ($path =~ /existing/i && $path !~ /#new/) {
        my $page = FakeCatalystObject->new;
        $page->{path} = $path;
        return [$page], undef;
    } else {
        return [], [{path => $path}];
    }
}

sub cache {
    my ($self, $c) = @_;
    return undef;
}


sub redirect {
    my ($self, $url) = @_;
    $self->{url}=$url if $url;
    return $self->{url};
}

sub uri_for {
    my ($self, $url) = @_;
    return $url;
}

sub loc {
    my ($self, $text) = @_;
    return "Faking localization... $text ...fake complete.";
}

sub session {
    my ($self, $c) = @_;
    return '';
}

sub pref {
    my ($self, $c, $setting, $value) = @_;
    return '' if not defined $setting;
    return $prefs{$setting} || '' if not defined $value;
    $prefs{$setting} = $value;
}

sub sessionid {
    return 0;
}

1;