How can I match fully qualified identifier under cursor?

I'm searching for a way to collect from a script something like `::std::unique_ptr` or `MyNamespace::MyClassName` depending where cursor is located when editing line `::std::unique_ptr<MyNamespace::MyClassName>`

Thanks!