Skip to content

Commit 58c91f3

Browse files
author
Alexis Sukrieh
committed
documentation updates
1 parent caa2c94 commit 58c91f3

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

lib/Dancer2/Plugin/ProbabilityRoute.pm

+22-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ route as long as they don't purge their cookies.
2828
"A is returned for you";
2929
},
3030
50 => sub {
31-
"A is returned for you";
31+
"B is returned for you";
3232
}
3333
};
3434
@@ -45,16 +45,25 @@ my $_routes = {};
4545

4646
=method probability_route
4747
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).
5253
5354
Here is an example of a 30, 50, 20 split:
5455
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+
};
5867
5968
To provide stability for each user, the session ID is used as a pivot, to build
6069
a I<user_score>, which is an number between 0 and 99.
@@ -82,7 +91,7 @@ register 'probability' => sub {
8291
$route_score += $probability;
8392
push @_probability_routes, [$probability, $code];
8493
}
85-
94+
8695
if ($route_score < 100) {
8796
croak "Probability for route is lower than 100 ($route_score)";
8897
}
@@ -149,4 +158,8 @@ L<Fabrice Gabolde|https://metacpan.org/author/FGA> contributed heavily to the
149158
design and helped me make this module so easy to write it took less than half
150159
a day to get it into CPAN.
151160
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+
152165
=pod

0 commit comments

Comments
 (0)