or download this
my @pre_events = (qw(focus));
my @post_events = (qw(blur));
...
$mech->field('#username', 'admin', undef, \@pre_events, \@post_events)
+;
$mech->field('#password', '*******', undef, \@pre_events, \@post_event
+s);
$mech->click_button(id => 'loginBtn');