From my understanding it is legal(although I'm not a lawyer), but if you are going to redistribute it, you must give credit where credit is due.
Although, I would suggest keeping it in a seperate file, perhaps changing the package name
or something like that. Then you could just distribute it with your PM file.