@@ -28,7 +28,7 @@ route as long as they don't purge their cookies.
28
28
"A is returned for you";
29
29
},
30
30
50 => sub {
31
- "A is returned for you";
31
+ "B is returned for you";
32
32
}
33
33
};
34
34
@@ -45,16 +45,25 @@ my $_routes = {};
45
45
46
46
=method probability_route
47
47
48
- Use this keyword to declare a route that gets triggered only under a given
49
- probability.
50
- The sequence is important: the first declaration for a given method/path tuple
51
- is the default version of the route.
48
+ Use this keyword to declare a route that is devided into multiple versions,
49
+ each them triggered for a certain percentage of users.
50
+
51
+ The sequence is important: the first declaration is the default version of
52
+ the route (if the user has no cookies).
52
53
53
54
Here is an example of a 30, 50, 20 split:
54
55
55
- probability_route 30, 'get', '/' => sub { "30% chances to get there" };
56
- probability_route 50, 'get', '/' => sub { "50% chances to get there" };
57
- probability_route 20, 'get', '/' => sub { "20% chances to get there" };
56
+ get '/test' => probability
57
+ 30 => sub {
58
+ "30% of users see that.";
59
+ },
60
+ 50 => sub {
61
+ "50% of users see that.";
62
+ },
63
+ 20 => sub {
64
+ "20% of users see that.";
65
+ },
66
+ };
58
67
59
68
To provide stability for each user, the session ID is used as a pivot, to build
60
69
a I<user_score > , which is an number between 0 and 99.
@@ -82,7 +91,7 @@ register 'probability' => sub {
82
91
$route_score += $probability ;
83
92
push @_probability_routes, [$probability , $code ];
84
93
}
85
-
94
+
86
95
if ($route_score < 100) {
87
96
croak " Probability for route is lower than 100 ($route_score )" ;
88
97
}
@@ -149,4 +158,8 @@ L<Fabrice Gabolde|https://metacpan.org/author/FGA> contributed heavily to the
149
158
design and helped me make this module so easy to write it took less than half
150
159
a day to get it into CPAN.
151
160
161
+ The second release was made thanks to the observations of
162
+ L<Russell Jenkins|http://search.cpan.org/~russellj/> who suggested a better API,
163
+ allowing for a more straight-forward approach.
164
+
152
165
=pod
0 commit comments