Use digital potentiometer and transistor to drive pigtailed laser diode

There is one thing I forgot to say:
I need to modulate the power of laser diode.
Does DAC can do this? Or just write code to modulate?