The formation of singularities of self-focusing solutions of the nonlinear Schrödinger equation (NLS) in critical dimension is characterized by a delicate balance between the focusing nonlinearity and diffraction (Laplacian), and is thus very sensitive to small perturbations. In this paper we introduce a systematic perturbation theory for analyzing the effect of additional small terms on self-focusing, in which the perturbed critical NLS is reduced to a simpler system of modulation equations that do not depend on the spatial variables transverse to the beam axis. The modulation equations can be further simplified, depending on whether the perturbed NLS is power conserving or not. We review previous applications of modulation theory and present several new ones that include dispersive saturating nonlinearities, self-focusing with Debye relaxation, the Davey--Stewartson equations, self-focusing in optical fiber arrays, and the effect of randomness. An important and somewhat surprising result is that various small defocusing perturbations lead to a generic form of the modulation equations, whose solutions have slowly decaying focusing-defocusing oscillations. In the special case of the unperturbed critical NLS, modulation theory leads to a new adiabatic law for the rate of blowup which is accurate from the early stages of self-focusing and remains valid up to the singularity point. This adiabatic law preserves the lens transformation property of critical NLS and it leads to an analytic formula for the location of the singularity as a function of the initial pulse power, radial distribution, and focusing angle. The asymptotic limit of this law agrees with the known loglog blowup behavior. However, the loglog behavior is reached only after huge amplifications of the initialamplitude, at which point the physical basis of NLS is in doubt. We also include in this paper a new condition for blowup of solutions in critical NLS and an improved version of the Dawes--Marburger formula for the blowup location of Gaussian pulses.