Actor Sir Ian McKellen is joining the cast of ITV1's soap Coronation Street to play a "dodgy novelist".