There is two main aspects to this, one is a failing in Iran's counter-intelligence and security apparatus. The other aspect is that many of these figures seek shahadat. This means they do not take the level of precaution needed. This second issue is obviously more sensitive and tricky to deal with as this has become a cultural aspect of many Iranians in the religious community. I believe if you played (not necessary even still play) an important role in Iran's program, then you cannot be lax in your security. If this cannot be done, then the internal security must become much more robust to make up for this.
Public perception is not very important to me personally as ultimately what matters in my opinion is us obtaining our goals. However as expected, this attack has caused a negative shift in perception towards Iran even among strong supporters of Iran. One could argue the Iranian establishment cannot afford to continuously take these hits and seemingly reply with mere words (openly anyway) as they will start to lose too much credibility. The counterargument to this is of course that is who has the last laugh that wins i.e these loses are fleeting.
Regardless, of what you believe, there is clearly a foreign backed network in Iran that is quite well organised that is coordinating these attacks. They need to be dismantled. We need a serious spring cleaning in our intelligence forces. As things stand, they're not up to the job.