“FOR THE Man Who Has Everything” is one of Superman’s classic tales, told more than 30 years ago by writer Alan Moore and artist Dave Gibbons, the same legendary comic-book duo who gave us “Watchmen.” Last night, CBS’s “Supergirl,” channeled that Moore and Gibbons story — and gave us one of the show’s best episodes yet.

“Supergirl’s” producers seem to have taken a note from the Justice League cartoons by realizing that this great Superman tale may not find a big-screen home any year soon, yet can sure make for great television.

Specifically, the episode mirrors the “Man Who Has Everything” plot line, as an alien parasite possessing telepathic powers creates a strong illusion within Supergirl of the life she never had — but has long wanted. Kara/Supergirl’s war-hungry uncle Non has unleashed a Black Mercy plant on her to try to keep her out of the way when his renegade Kryptonians plan their next strike to take over Earth.

Kara is in a deep, sedative trance while mentally whisked away to her dreams. She wakes up in her Kryptonian bedroom, with her mother and father alive. Even her young cousin and future Superman, Kal-El, is there for the family get-together, having never had to be shipped off to Earth because, well, everything is great on Krypton.

It’s a wonderful family moment that is literally too good to be true. Kara’s dream is giving her everything she wants to see and hear. The Black Mercy’s telepathic powers use Kara’s desires as fuel to produce the exact setting she wants, even down to the Kryptonian clothes. And there’s nothing superpowered in her dream setting; it’s just family. Kara is defiant at first, but the Black Mercy knows just the words to have her parents and young Kal-El say to lure Kara to fall into this mind-trap.

Meanwhile, back in Earth’s real world, Kara’s friends realize the only way to get her back is to send someone into her mind and bring her out. Someone needs to convince her that everything isn’t real where she is, and that she needs to come home.

Fortunately, Maxwell Lord is being illegally imprisoned in the secret government hideout that Kara and sister Alex work for, under the leadership of the always-in-disguise Martian Manhunter/Hank Henshaw. Lord constructs a device to help Alex get in Kara’s mind. When Alex gets there, she’s met with resistance from everyone, including Kara.

We all know how this story ends. The fantasy is rejected, and Kara escapes with the help of her sister. But she returns to reality now angry. The Kyptonians have launched their attack, and she wants first dibs on her evil uncle. He made Kara lose her family all over again, and it felt just as real as the first time.

What Kara didn’t know is that it was her aunt Astra — despite being on the side of the evil Kryptonians — helped Alex defeat the Black Mercy. Astra betrayed her husband because she didn’t want her niece fallen in battle.

That nice moment, though, turns dark when Alex has to put a Kryptonite sword through Astra’s heart as she was moments away from killing the Martian Manhunter (in his full alien guise during the battle).

When the dust settles and the Kryptonians retreat, Kara is called over to her dying aunt. They say their goodbyes, and then Astra is gone. The Martian Manhunter lies, telling Kara he had to kill Astra, because he doesn’t want to ruin the relationship between Kara and adoptive sister Alex. We’ll see how long that lie can hold up.

An emotional episode ends with Kara back with her friends and family. Everything is back to normal. Kara and Winn are friends again, following their awkward kiss. There’s no awkward sexual tension between Kara and Jimmy (for now). And Kara and Alex are just as close as ever, especially after Alex helped save Kara’s life from the Black Mercy.

But what happens when Kara finds out that Alex killed Astra? Because we know the truth — as if emerging from a dream-state — will come out eventually.